noalloc: Tooling and libraries to enforce zero heap allocations in Golang The Consensus Labs released noalloc, an experimental Go tool that checks an entire call tree for heap allocations from functions marked with a //noalloc:root directive, exiting 1 when it finds an allocation and 2 when it cannot run. The tool requires Go 1.27 or later and ships with the bounded package, which provides four fixed-capacity containers — Buf, Vec, Slice and Map — plus a JSON encoder and decoder, and it is used in production at The Consensus in both its web service and code search engine. The repository and README were written entirely by AI under human guidance, and the project is described as experimental and subject to large changes. Disclaimer: This repo is entirely written by AI. The README is largely written by AI. It is guided by a human and used in production at The Consensus in both the web service and our code search engine. It is experimental and may change vastly. It's one thing to be able to write some code that doesn't allocate on the heap. It's another thing to be able to keep code from not allocating as the code changes. With noalloc you can assert Golang functions should not allocate and the noalloc CLI will check the entire call tree from that function for heap allocations. noalloc will tell you every line that allocates, allowing you to remediate or exempt lines. noalloc also provides zero-allocating, fixed-sized data structures and algorithms including a JSON encoder and decoder to make it easier and cleaner to write code that does not allocate. go install github.com/theconsensuslabs/noalloc/cmd/noalloc@latest You'll need Go 1.27 or later. For example, mark a function with //noalloc:root and run noalloc in its module. //noalloc:root func c Counter Add name string, n int string { c.counts name += n return name + "=" + strconv.Itoa c.counts name } bash $ noalloc counter.go:11: example.com/counter.Counter .Add: map write counter.go:12: example.com/counter.Counter .Add: calls strconv.Itoa; string concatenation; escapes: name + "=" + ~r0 escapes to heap noalloc exits 1 it found an allocation or 2 it couldn't run at all . It allows allocations on an error or panic that ends the root's call and in first-use setup, which the caveats below cover. - //noalloc:root checks a function and everything it calls. - //noalloc:exempt