Diagnosing Garbage Collection Pauses
In latency-critical services, small short-lived allocations create severe GC CPU overhead.
Essential Commands
scripts/pprof-inspect.sh
# Capture 30s CPU profile
go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30
# Inspect heap allocations
go tool pprof -alloc_space http://localhost:6060/debug/pprof/heapZero-Allocation Techniques
- Use
sync.Poolfor heavy temporary buffers. - Preallocate slice capacity when length is known:
make([]byte, 0, expectedLen). - Pass pointers only when escaping to heap is intentional.
Personal engineering field notes compiled from production systems. Patterns and benchmarks are updated as runtimes evolve.