Memory ballast
Memory ballast in Go, at its core, is like putting a heavy suitcase in the trunk of a car to prevent it from being too light and skidding on ice. In Go’s context, a memory ballast is a large allocation of memory that is never used but serves to influence the behavior of the garbage collector.
Traditionally, Go’s GC would trigger based on the heap size doubling from the size at the end of the last collection (GOGC=100
). In applications with large heap sizes, this could lead to long periods between GC cycles, followed by large, disruptive collections.
Developers used memory ballast as a buffer, artificially increasing the heap size to prompt more frequent, but smaller and less disruptive, GC cycles. It was a manual tuning method to optimize performance, particularly in high-throughput, low-latency systems. This technique was developed by the streaming company Twitch in 2019 in their post How I learnt to stop worrying and love the heap (https://blog...