golang-performance

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

Updated Jun 15, 2026
One-click install
npx skills add https://github.com/2877389577/novels_ai_gen --skill golang-performance-2877389577
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-performance
Source: https://github.com/2877389577/novels_ai_gen/tree/main/.agents/skills/golang-performance
Command: npx skills add https://github.com/2877389577/novels_ai_gen --skill golang-performance-2877389577

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Go services often suffer from hidden bottlenecks—excessive allocations, GC pauses, cache misses, lock contention, or slow I/O—and intuition about the cause is wrong most of the time. This Skill provides a disciplined measure-first methodology plus a catalog of proven optimization patterns mapped to specific bottleneck signals. ## Core Features & Use Cases - Decision-tree diagnosis: Maps pprof/fgprof signals (alloc_objects, CPU profile, goroutine blocks) to the right optimization category: memory, CPU, runtime tuning, I/O, or caching. - Iterative optimization workflow: Enforces baseline benchmarks with -benchmem -count=6, one change at a time, and benchstat comparison for statistical significance. - Deep-dive references: Covers allocation reduction, sync.Pool, struct alignment, inlining, cache locality, false sharing, SIMD, HTTP transport tuning, JSON performance, GC tuning (GOGC/GOMEMLIMIT), and Prometheus-based production observability. - Use Case: Your Go API has p99 latency of 2s with only 5% CPU usage. The Skill directs you to fgprof for off-CPU analysis, identifies a misconfigured http.Transport (MaxIdleConnsPerHost=2), and guides a verified fix with before/after benchstat evidence. ## Quick Start Ask the agent to review your Go package or hot-path function for performance bottlenecks and suggest profile-guided optimizations.

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—intuition is wrong about 80% of the time. Then write an atomic benchmark, measure a baseline with -benchmem -count=6, apply one optimization at a time, and verify with benchstat.

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 tool should I use when Go CPU profile shows nothing but latency is high?▼

Use fgprof, which captures both on-CPU and off-CPU (I/O wait) time. Standard pprof CPU profiles miss time spent blocked on network, database, or filesystem calls, which is the likely cause when CPU usage is low but latency is high.

Does struct field order affect memory usage in Go?▼

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

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

Go maps never release bucket memory when entries are deleted—a map that held millions of keys retains that allocation forever. Replace the map with a fresh make() allocation so the old bucket array becomes eligible for garbage collection.

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

Avoid pooling objects larger than about 32KB, since large allocations bypass pool size classes and GC handles them efficiently. Also skip pooling for infrequently used objects where pool overhead exceeds the allocation savings.