Thanks to efficient in-built memory management in the Go runtime, we’re generally able to prioritise correctness and maintainability in our programs without much consideration for the details of how allocations are occurring. From time to time though, we may discover performance bottlenecks in our code, and want to look a little deeper.
Anyone who’s run a benchmark with the
-benchmem flag will have seen the
allocs/op stat in output like the below. In this post we’ll look at what counts as an alloc and what we can do to influence this number.