Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Adventures in Cgo Preformance

Adventures in Cgo Preformance

Cgo is a powerful tool in the Go programmer’s arsenal. It allows Go programmers to interoperate with other languages. However, Cgo documentation is scarce and best practices for performance are hard to come by. In this tutorial session, I discuss lessons I've has learned working on the Go API for Wallaroo, a high-performance distributed stream processor written in Pony.

I cover hard-won knowledge about using Cgo in performance sensitive code including: ways in which Cgo makes interoperation with other languages difficult, how you can work around common sources of performance and scaling problems, and an issue with the Go runtime that can't be worked around.

Sean T Allen

August 29, 2018
Tweet

More Decks by Sean T Allen

Other Decks in Technology

Transcript

  1. SEAN T. ALLEN VP OF ENGINEERING AT WALLAROO LABS AUTHOR

    OF “STORM APPLIED” MEMBER OF THE PONY CORE TEAM LOVER OF ARTISANAL STREET ART @SEANTALLEN @WALLAROOLABS @PONYLANG
  2. TO MY EYE, CGO IS NOT FFI* * except it

    is according to Wikipedia
  3. CALLING “C” FROM GO METHOD OPERATIONS COMPLETED NANOS PER OPERATION

    CGO 10,000,000 171 NS/OP GO 2,000,000,000 1.83 NS/OP * according to a simple Cockroach Labs benchmark
  4. CALLING GO FROM C TEST MACHINE MILLISECONDS PER OPERATION AWS

    (various instance types) 1-2 MS/OP 2014 MacBook Pro 5-6 MS/OP * according to a simple Sean T. Allen benchmark
  5. THERE ARE MORE TYPES OF GARBAGE COLLECTION IN HEAVEN AND

    EARTH THAN ARE DREAMT OF IN YOUR PHILOSOPHY
  6. AND BAD THINGS HAPPEN IF YOU DON’T FOLLOW THE RULES

    • Go code may pass a Go pointer to C provided the Go memory to which it points does not contain any Go pointers • C code may not keep a copy of a Go pointer after the call returns • A Go function called by C code may not return a Go pointer • Go code may not store a Go pointer in C memory.