Go Runtime Performance
Focus this module
- Benchmark first, then optimize.
- Optimize one variable at a time.
- Keep a baseline before every change.
Allocation control
-benchmemfor alloc counts- avoid
fmtand unnecessary copies in hot paths - pre-size containers
GC and heap
- GC pressure is about live memory
- prefer lower retained set and smaller pointer graphs
- tune
GOGCandGOMEMLIMITwith measured trade-offs
Scheduler
- M/P/G model
- avoid tiny goroutines for tiny work
- bound concurrency for CPU-bound work
Memory model
- define happens-before edges before optimization
- channels, locks, atomics
- immutable snapshots for lock-free reads
Generics
- generics can be faster than expected, but benchmark anyway
- avoid broad constraints and
anyboxing in hot code
Final workflow
- 1) baseline
- 2) single-target change
- 3) compare before/after
- 4) lock in with regression checks
1 / 1