Manish Jain - High Performance Manual Memory Management in Go

The idea is that you laydown structs into byte-slices (using one of the 3 different methods mentioned in the talk), and then lay down many of these bytes slices onto bigger slices. So, from Go’s perspective, you took 64MB byte slice, but then laid down milllions of structs on that one allocation. Now, GC does not need to do a lot of scan, because you only allocated that one byte slice.

Becomes even better when you allocate even that byte slice from jemalloc – I’ve found jemalloc memory management to be a lot more predictable and work better with the system than Go’s.

Of course, if your struct was not allocated on heap to begin with, then there won’t be much value in converting it to a byte slice.

1 Like