Summary
We’ve explored GC, the difference between stack and heap allocation, and ways to optimize memory usage for better performance. Also, we’ve uncovered the evolution of Go’s garbage collector and its methods, including advanced topics such as its algorithm (tri-color/concurrent/mark and sweep).
We’ve also discussed practical approaches including using environmental variables such as GOGC
to fine-tune garbage collection and employing techniques such as memory ballast and GOMEMLIMIT
to help the GC manage the program memory.
During this chapter, you probably ask yourself: How much performance are we gaining, tinkering, and tweaking the GC and runtime parameters, and combining these techniques?
The answer is simple: Performance is not a guessing game. We should measure it.
In the next chapter (on analyzing performance), we’ll explore how to profile our application in terms of memory, CPU, allocations, and much more.