Detects performance anti-patterns and applies optimization techniques in Go. Covers allocations, benchmarks with benchstat, pprof profiling, GC/GOMEMLIMIT tuning, PGO, and HTTP client reuse. Use when checking performance, finding slow code, reducing allocations, profiling, or reviewing hot paths.
Ships in go-agent-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Profile first, optimize second. Never optimize without a benchmark proving the problem.
Detailed reference material, loaded on demand:
references/benchmarking.md — benchmark shape, running, reading
benchstat, comparing variants, commit format, CI regression checks.references/memory-and-io.md — allocation, hot-path and map examples,
retention, struct layout, false sharing, HTTP clients, streaming, batching.references/profiling.md — which profile for which symptom, capture
commands, reading pprof, compiler diagnostics, traces, flight recorder.references/runtime-tuning.md — GOGC/GOMEMLIMIT, reading gctrace,
GOMAXPROCS in containers, PGO.references/logging.md — slog vs zap/zerolog decision table, slog with a
zap backend, logging anti-patterns in hot paths.Read a reference file only when the summary below is not enough.
allocs/op, RSS. Without a target, optimization never ends.net.(*conn).Read or database/sql, or a trace dominated by one
upstream span, mean the fix is elsewhere (go-database, go-observability).go test -run '^$' -bench Name -benchmem -count=10 | tee old.txt.benchstat old.txt new.txt shows a significant difference.perf(scope): ...).strconv instead of fmt.Sprintf for single values.strings.Builder (with Grow when the size is known) instead of +=
in loops.make([]T, 0, n), make(map[K]V, n).sync.Pool — reset on get,
size-cap on put (the concurrency skill has the pattern).[]byte(s)/string(b) conversions, and anything
go build -gcflags=-m reports as escapes to heap.reflect on hot paths; generate code instead (stringer, protobuf).[]Point over []*Point, and a
struct of slices when a loop touches one field of many records.sync.Map only for its two documented workloads; otherwise a map
guarded by a mutex.Examples for sections 1-3: references/memory-and-io.md.
func BenchmarkParse(b *testing.B) {
input := makeInput(4 << 10) // setup runs once, outside the timed loop
b.ReportAllocs()
for b.Loop() { // Go 1.24+: no ResetTimer, no sink variable
Parse(input)
}
}
-count=10 and benchstat, never a single run. ~ in its output means
"no change", whatever the percentage says.for range b.N with b.ResetTimer() after setup and
a package-level sink.Commands, reading guide and CI regression checks: references/benchmarking.md.
| Symptom | First profile |
|---|---|
| High CPU | CPU profile — high flat functions |
| GC busy, high allocation rate | heap with -sample_index=alloc_objects |
| Memory grows over time | two heap snapshots, go tool pprof -base |
| Latency high, CPU idle | goroutine dump, block/mutex profiles, a trace |
| Lock contention | mutex profile (runtime.SetMutexProfileFraction) |
| Scheduling delays, GC pauses | execution trace; flight recorder (Go 1.25+) in production |
go test -run '^$' -bench Name -cpuprofile cpu.out -memprofile mem.out ./pkg
go tool pprof -http=:0 cpu.out # flame graph
go build -gcflags='-m' ./pkg 2>&1 | grep 'escapes' # what moves to the heap
The CPU profile only sees running goroutines: when latency is high and CPU
is low, the time is waiting, and only the goroutine, block and trace views
show it. Commands, reading guide, escape analysis and the flight recorder:
references/profiling.md.
Importing net/http/pprof registers its handlers on http.DefaultServeMux.
If the service also serves public traffic from DefaultServeMux, profiles,
command line and goroutine stacks become world-readable. Always give pprof
its own loopback or internal-network listener.
GOMEMLIMIT to ~80-90% of the memory limit and keep
GOGC; the GC then works harder near the ceiling instead of the process
being OOM-killed. Never GOGC=off with only a limit.GOMAXPROCS from the cgroup CPU limit — remove
automaxprocs and don't set it by hand without a measurement.default.pgo for PGO (Go 1.21+).Detail, gctrace reading and runtime/metrics: references/runtime-tuning.md.
http.Client per process, with a Timeout and a transport cloned
from http.DefaultTransport with MaxIdleConnsPerHost raised — the
default of 2 churns connections under concurrency.r.Body with a size cap instead of io.ReadAll;
io.Copy for proxying; bufio for many small writes.slices.Clone/strings.Clone what you keep.Examples, struct layout and false sharing: references/memory-and-io.md.
log/slog is the default. Switch only when a benchmark shows logging in
the profile, and then keep the slog API with a faster backend (zap's
zapslog handler) so callers never change. In hot loops, log progress
every N items or a summary after the loop — never once per item.
Decision table and examples: references/logging.md.
| Anti-Pattern | Fix |
|---|---|
fmt.Sprintf for simple int→string | strconv.Itoa |
| String concatenation in loop | strings.Builder |
| Slice without preallocation | make([]T, 0, n) |
| Map without capacity hint | make(map[K]V, n) |
regexp.Compile inside function | Compile once at package level |
json.Marshal in hot path | Profile first: since Go 1.27 encoding/json runs on the faster v2 engine; code-gen (easyjson) only if JSON still dominates |
| Logging in tight loop | Batch or sample |
defer in very tight inner loop | Manual cleanup (rare, benchmark first) |
http.Get / default client in production | Shared client with Timeout and tuned transport |
io.ReadAll on request or response bodies | Stream with a decoder and a size cap |
reflect.DeepEqual outside tests | slices.Equal, maps.Equal, bytes.Equal |
panic/recover as control flow | Return errors — a panic captures a stack trace |
Most Go code is not performance-critical. Readability and correctness ALWAYS take priority over micro-optimizations. Only apply these patterns when:
Premature optimization is still the root of all evil, even in Go.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
35 skills in this plugin
/git-commitStructured git commit messages following Conventional Commits format for Go projects. Generates well-scoped, atomic commits with clear descriptions. Use when committing changes, writing commit messages, preparing PRs, or reviewing commit history quality. Trigger examples: "commit these changes", "create commit", "commit message", "prepare PR", "squash commits". Not for: code review (go-code-review), changelog generation.
/go-api-designHTTP/REST API design for Go services: handlers, ServeMux routing, middleware, request validation, pagination, idempotency, health checks, error responses, and graceful shutdown. Use when designing APIs, writing HTTP handlers, implementing middleware, or structuring REST endpoints. Trigger examples: "design API", "REST endpoints", "HTTP handler", "middleware pattern", "graceful shutdown", "API versioning". Not for: gRPC services (go-grpc), spec-first OpenAPI work (go-openapi), general architecture (go-architecture-review), concurrency in handlers (go-concurrency-review).
/go-architecture-reviewReview Go project architecture: package structure, dependency direction, layering, separation of concerns, domain modeling, and module boundaries. Use when reviewing architecture, designing package layout, evaluating dependency graphs, or refactoring monoliths into modules. Trigger examples: "review architecture", "package structure", "project layout", "dependency direction", "clean architecture Go", "module boundaries". Not for: code-level style (go-coding-standards), endpoint design (go-api-design).
/go-agent-skills:go-performance-reviewfrom go-agent-skills
npx claudepluginhub eduardo-sl/go-agent-skills --plugin go-agent-skillsOther plugins' skills for the same job