golang-performance

Diagnose and fix Go performance bottlenecks using profiling-driven optimization patterns.

1|Updated May 25, 2020
One-click install
npx skills add https://github.com/titaneric/dotfiles --skill golang-performance-titaneric
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-performance
Source: https://github.com/titaneric/dotfiles/tree/main/dot_agents/skills/golang-performance
Command: npx skills add https://github.com/titaneric/dotfiles --skill golang-performance-titaneric

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires benchstat, and includes references (resource) components.

What problem does it solve? Go developers often optimize the wrong code because intuition about bottlenecks is wrong most of the time. This Skill provides a disciplined, profile-first methodology that maps specific bottleneck signals (high allocations, CPU-bound loops, GC pauses, I/O waits) to the exact optimization pattern that fixes them. ## Core Features & Use Cases - Decision-tree diagnosis: Maps pprof and fgprof signals to targeted fixes across memory, CPU, I/O, runtime, and caching domains. - Iterative optimization workflow: Enforces baseline benchmarks, one change at a time, and benchstat comparison for statistical significance. - Deep-dive references: Covers allocation reduction, sync.Pool, struct alignment, cache locality, false sharing, HTTP transport tuning, JSON performance, and GC tuning with GOMEMLIMIT. - Use Case: A service shows high p99 latency but low CPU usage. The Skill directs you to fgprof for off-CPU analysis, identifies blocked goroutines on database calls, and guides connection pool tuning instead of wasted micro-optimization. ## Quick Start Ask the agent to review your Go package for performance bottlenecks and suggest profile-driven optimizations with benchmarks.

Frequently Asked Questions about golang-performance

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize Go code performance after profiling?

Follow the iterative cycle: define a metric, write an atomic benchmark, measure a baseline with -benchmem and -count=6, apply one optimization at a time, then compare with benchstat. Use the decision tree to map your pprof signal to the right fix.

What tool should I use when Go CPU profiling shows nothing but latency is high?

Use fgprof, which captures both on-CPU and off-CPU time such as I/O wait and blocked goroutines. Standard pprof CPU profiles only sample on-CPU time, so external bottlenecks like database calls appear invisible.

How do I reduce allocations in Go hot paths?

Reuse slice backing arrays with append(s[:0], ...), preallocate maps with size hints, use sync.Pool for short-lived objects under 32KB, and avoid interface boxing with generics. Verify with go test -bench -benchmem to track allocs/op.

Does struct field order affect memory usage in Go?

Yes. Go adds padding to satisfy alignment requirements, so ordering fields from largest to smallest reduces struct size. Run the fieldalignment tool to detect structs with wasted padding automatically.

When should I not use sync.Pool in Go?

Avoid pooling objects larger than 32KB, infrequently allocated objects, and buffers returned to callers who may retain them. Always reset state before Put and return copies rather than pooled memory.

Why does my Go map keep using memory after deleting keys?

Go maps never release bucket memory when entries are deleted, so a map that held millions of keys retains its peak allocation. Replace the map with a fresh make() to let the old bucket array be garbage collected.