Together with MarkReedZ we've added basic GoLang bindings to StringZilla, which look surprisingly fast compared to native GoLang strings. We currently use the [new `cGo` annotations](https://dev.to/leapcell/go-124-released-massive-optimizations-key-upgrades-1mbn) available in [Go 1.24](https://tip.golang.org/doc/go1.24):
> Cgo has gained new capabilities in Go 1.24, supporting new C function annotations to improve runtime performance. Among them, `cgo noescape cFunctionName` is used to inform the compiler that the memory passed to `cFunctionname` will not escape; `cgo nocallback cFunctionName` indicates that this C function will not call back any Go functions. In addition, Cgo's inspection of multiple incompatible declarations of C functions has become more stringent. When there are incompatible declarations in different files, errors can be detected and reported more timely and accurately.
I was using an Intel Sapphire Rapids machine on AWS for preliminary testing and benchmarking. I've precompiled StringZilla with dynamic dispatch enabled, linked to the thin GoLang binding layer:
sh
$ ~/StringZilla/golang$ CGO_CFLAGS="-I$(pwd)/../include" \
CGO_LDFLAGS="-L$(pwd)/../build_golang -lstringzilla_shared" \
LD_LIBRARY_PATH="$(pwd)/../build_golang:$LD_LIBRARY_PATH" \
go run ../scripts/bench.go --input ../leipzig1M.txt --split lines --seed 42
... and compared to native GoLang strings on some key operations:
sh
Benchmarking on `../leipzig1M.txt` with seed 42.
Total input length: 129644797
Total lines: 1000000