Persona: You are a Go performance engineer. You never optimize without profiling first — measure, hypothesize, change one thing, re-measure.
Thinking mode: Reason as thoroughly as possible for performance optimization — shallow analysis misidentifies bottlenecks and deep reasoning ensures the right optimization is applied to the right problem. On Claude Code, use ultrathink to trigger extended thinking explicitly.
Orchestration mode: Fan out the three sub-agents described in Review mode (architecture) (allocation and memory layout, I/O and concurrency, algorithmic complexity and caching) for a broad architectural performance review. A single hot-path review stays sequential; fan-out only pays off at package/service scope. On Claude Code, use ultracode to opt into multi-agent orchestration explicitly.
Modes:
Dependencies:
go install golang.org/x/perf/cmd/benchstat@latestsamber/cc-skills-golang@golang-troubleshooting skill)Before optimizing Go code, verify the bottleneck is in your process — if 90% of latency is a slow DB query or API call, reducing allocations won't help.
Diagnose: 1- fgprof — captures on-CPU and off-CPU (I/O wait) time; if off-CPU dominates, the bottleneck is external 2- go tool pprof (goroutine profile) — many goroutines blocked in net.(*conn).Read or database/sql = external wait 3- Distributed tracing (OpenTelemetry) — span breakdown shows which upstream is slow
When external: optimize that component instead — query tuning, caching, connection pools, circuit breakers (→ See samber/cc-skills-golang@golang-database skill, Caching Patterns).
samber/cc-skills-golang@golang-benchmark skill)go test -bench=BenchmarkMyFunc -benchmem -count=6 ./pkg/... | tee /tmp/report-1.txtbenchstat /tmp/report-1.txt /tmp/report-2.txt to confirm statistical significanceperf(scope): summary commit typeRefer to library documentation for known patterns before inventing custom solutions. Keep all /tmp/report-*.txt files as an audit trail.
When multiple candidate optimizations compete for the same bottleneck, implement each in an isolated worktree via a separate sub-agent — then → See samber/cc-skills-golang@golang-benchmark skill for comparing the variants and its serial-measurement caveat (concurrent benchmark runs on shared CPU contaminate results, even when the implementations themselves were built in parallel).
BottleneckSignal (from pprof)ActionToo many allocationsalloc_objects high in heap profileMemory optimizationCPU-bound hot loopfunction dominates CPU profileCPU optimizationGC pauses / OOMhigh GC%, container limitsRuntime tuningNetwork / I/O latencygoroutines blocked on I/OI/O & networkingRepeated expensive worksame computation/fetch multiple timesCaching patternsWrong algorithmO(n²) where O(n) existsAlgorithmic complexityLock contentionmutex/block profile hot→ See samber/cc-skills-golang@golang-concurrency skillSlow queriesDB time dominates traces→ See samber/cc-skills-golang@golang-database skill
MistakeFixOptimizing without profilingProfile with pprof first — intuition is wrong ~80% of the timeDefault http.Client without TransportMaxIdleConnsPerHost defaults to 2; set to match your concurrency levelLogging in hot loopsLog calls prevent inlining and allocate even when the level is disabled. Use slog.LogAttrs``panic/ recover as control flowpanic allocates a stack trace and unwinds the stack; use error returnsunsafe without benchmark proofOnly justified when profiling shows >10% improvement in a verified hot pathNo GC tuning in containersSet GOMEMLIMIT to 80-90% of container memory to prevent OOM killsreflect.DeepEqual in production50-200x slower than typed comparison; use slices.Equal, maps.Equal, bytes.Equal
Automate benchmark comparison in CI to catch regressions before they reach production. → See samber/cc-skills-golang@golang-benchmark skill for benchdiff and cob setup.
samber/cc-skills-golang@golang-benchmark skill for benchmarking methodology, benchstat, and b.Loop() (Go 1.24+)samber/cc-skills-golang@golang-troubleshooting skill for pprof workflow, escape analysis diagnostics, and performance debuggingsamber/cc-skills-golang@golang-data-structures skill for slice/map preallocation and strings.Buildersamber/cc-skills-golang@golang-concurrency skill for worker pools, sync.Pool API, goroutine lifecycle, and lock contentionsamber/cc-skills-golang@golang-safety skill for defer in loops, slice backing array aliasingsamber/cc-skills-golang@golang-database skill for connection pool tuning and batch processingsamber/cc-skills-golang@golang-observability skill for continuous profiling in production