A detailed walkthrough of porting Go's strings and bytes standard library packages to C, covering UTF-8 and bit manipulation dependencies, memory allocator design (inspired by Zig/Odin), buffer and builder types, and benchmarking infrastructure. The author introduces explicit allocators as a clean alternative to hidden malloc calls, ports Go's testing.B benchmarking in ~300 lines, and investigates two performance issues: a 20x slowdown in string search fixed by switching to memchr, and a strings.Builder regression traced to missing function inlining rather than the initially suspected return-type ABI issue. Final benchmarks show the C versions are 1.3–4x faster than Go for most operations, with Go winning only on Index/IndexByte due to hand-written assembly.

17m read timeFrom antonz.org
Post cover image
Table of contents
Bits and UTF-8BytesAllocatorsBuffers and buildersBenchmarksOptimizing searchOptimizing builderWrapping up

Sort: