Go Runtime Performance

Focus this module

  • Benchmark first, then optimize.
  • Optimize one variable at a time.
  • Keep a baseline before every change.

Allocation control

  • -benchmem for alloc counts
  • avoid fmt and 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 GOGC and GOMEMLIMIT with 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 any boxing in hot code

Final workflow

  • 1) baseline
  • 2) single-target change
  • 3) compare before/after
  • 4) lock in with regression checks
1 / 1
Use arrow keys or click edges to navigate. Press H to toggle help, F for fullscreen.