Large volumes of infrastructure data in Go services, such as routing tables or cluster states, create significant overhead for the garbage collector. In Go 1.27.3, a map containing one million structures occupies 616 MiB in the heap, with 471 MiB attributed to pointer spans. A full runtime.GC() call takes 31.2 ms, and processing 2 GiB of short-lived traffic results in 2.75 seconds of CPU time spent solely on scanning the cache.
The cnfgo project offers an alternative by automatically generating flat, pointer-free representations of Go structures. It allows developers to keep original Go structures while compiling them into noscan tables and .cnf files that support direct memory mapping via mmap. The tool is written in pure Go, requires no external dependencies, and functions with CGO_ENABLED=0.
Benchmarking the standard unique.Make[string] approach shows limited efficiency for this use case. While interning strings reduces the heap size from 616.0 MiB to 556.1 MiB, the volume of scanned heap bytes remains unchanged at 471.0 MiB. Furthermore, the GC pause remains significant at 27.97 ms, and CPU usage under traffic load increases from 862 ms to 1.03 s due to the overhead of managing the weak pointer table.






