Leipzig Gophers
blog

🔗Hybrid Meetup #35 wrap-up

Cgo experiments

Hybrid meetup #35 took place 2023-04-18 19:00 at Basislager Leipzig and was all about Cgo.

Cgo allows to bridge C and Go. From C, we can connect to other languages, like C++, too. Use cases are legacy code or performance. Implementing a pseudo-random walk (using an LCG) in both Go and C shows that C can be up to 4x faster for this particular task.

 C               1         -1 29.553µs
GO               1         -1 84.303µs
 C            1000        -12 41.799µs
GO            1000         26 107.295µs
 C         1000000      -1810 22.837387ms
GO         1000000         -2 83.182797ms
 C      1000000000      15894 6.25975724s
GO      1000000000     -44632 25.620427056s

One example was concerned with wrapping ggml, a lightweight tensor library for machine learning - xcgoggml. A threading mystery remains.

Experiment details can be found here: https://github.com/miku/cgosamples

Zig cross-compilation

The zig compiler (LLVM) can build real staticly linked binaries from a Go project with C dependencies, such as sqlite3. Example repo: https://github.com/klingtnet/cross-compile-with-zigcc.

Misc

We also briefly discussed LLMs, as we ran alpaca model ggml-alpaca-7b-q4.bin in the background, which wrote some simple SQL and thought of a haiku about the Go programming language:

Did you find a nice haiku?

Join our meetup and let us know!