golang-performance

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

Updated Jun 30, 2026
One-click install
npx skills add https://github.com/santoshkal/chezmoi --skill golang-performance-santoshkal
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-performance
Source: https://github.com/santoshkal/chezmoi/tree/main/private_dot_config/opencode/skills/Golang/skills/golang-performance
Command: npx skills add https://github.com/santoshkal/chezmoi --skill golang-performance-santoshkal

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 tuning, and caching domains. - Iterative optimization workflow: Enforces a measure-baseline, change-one-thing, benchstat-compare cycle with statistical significance checks. - Concrete code patterns: Covers slice reuse via append(s[:0]), struct field alignment, sync.Pool rules, false sharing, cache locality, singleflight, and batching. - Use Case: Your Go API 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 AI to review your Go function or service for performance bottlenecks and recommend profiling steps plus the right optimization pattern for each hotspot found.

Frequently Asked Questions about golang-performance

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

FAQPage Schema
How do I optimize a slow Go function?▼

Profile first with pprof to find the actual bottleneck rather than guessing. Write an atomic benchmark, measure a baseline with -benchmem and -count=6, apply one optimization at a time, then compare results with benchstat for statistical significance.

How do I reduce memory allocations in Go hot paths?▼

Reuse slice backing arrays with append(s[:0], ...), preallocate maps and slices with size hints, use sync.Pool for frequently allocated short-lived objects, and avoid interface boxing by using typed parameters or generics.

What profiling tool should I use when Go CPU usage is low 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 show on-CPU time, so they appear empty when the bottleneck is external like a slow database or network call.

Does struct field order affect memory usage in Go?▼

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

When should I not use sync.Pool in Go?▼

Avoid sync.Pool for objects larger than about 32KB, infrequently allocated objects, and cases where callers retain references to pooled buffers. Always reset state before Put and return copies rather than the pooled buffer itself.

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 once held millions of keys retains its peak allocation. Replace the map with a fresh make() call so the old bucket array becomes eligible for garbage collection.