Reducing Allocations: sync.Pool and Arenas
Object reuse, sync.Pool, and reducing GC pressure
Why reduce allocations?
Each heap allocation triggers eventual GC work. Reducing allocations lowers GC frequency and pause durations, improving throughput and tail latency in high-traffic services.
Profiling first
Always profile before optimising. Use go test -benchmem and -alloc_space heap profiles to find the actual hot allocation paths. Do not optimise based on intuition.
All lessons in this course
- Stack vs Heap and Escape Analysis
- The Go Memory Model and Happens-Before
- Garbage Collector Internals
- Reducing Allocations: sync.Pool and Arenas