Performance optimisation expertise for Go. Use when profiling, benchmarking, reducing allocations, optimising hot paths, analysing latency, improving throughput, or working with pprof, benchstat, trace, Pyroscope, or fgprof.
PERF.md for the full profiling workflow, platform-specific notes,
and containerised tooling setup (Pyroscope, Grafana)go tool pprof cpu.profgo tool pprof -alloc_space mem.profgo tool trace trace.out for latency analysisnet/http/pprof endpoints in services for live profilingfgprof for wall-clock profiling (captures I/O wait + CPU)testing.B with b.ReportAllocs()go test -bench=. -benchmem -count=10benchstat old.txt new.txtb.ResetTimer() after expensive setuptee .perf/$(date +%Y-%m-%d)/bench.txtmake([]T, 0, expectedCap)make(map[K]V, expectedSize)sync.Pool for frequently allocated/deallocated objectsstrconv over fmt for primitive conversions (significantly faster)strings.Builder for string concatenation in loopsfmt.Sprintf in hot pathsgo build -gcflags='-m'sync.Map only for read-heavy workloads with stable keyssync.RWMutex for write-heavy workloadsruntime.GOMAXPROCS() awareness for CPU-bound workgo.uber.org/goleak in tests to detect goroutine leakshttp.Client and http.Transport — never create per-requestMaxIdleConns, MaxIdleConnsPerHost, IdleConnTimeoutcontext.WithTimeout for all outbound callsMaxConcurrentReconciles for the workloadclient.Reader (cached) for reads, client.Writer for writesgithub.com/grafana/pyroscope-go SDKPERF.md for Docker Compose and Kubernetes deploymentbd create "Perf: finding" --type note --labels perfAfter profiling, record findings in beads for persistent memory:
bd create "Perf: description of finding" --type note --labels perf,context
bd create "Baseline: metric at N resources" --type note --labels perf,baseline