golang-performance

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

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

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 profile-first methodology and a decision tree that maps pprof signals (allocations, CPU, GC pauses, I/O waits) to the correct optimization pattern, so fixes target the actual bottleneck. ## Core Features & Use Cases - Bottleneck Decision Tree: Maps profiling signals (heap profile, CPU profile, goroutine blocks) to the right fix across memory, CPU, I/O, runtime, and caching domains. - Iterative Optimization Cycle: Enforces define-metric, baseline 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, cache locality, false sharing, HTTP transport tuning, JSON performance, GC tuning with GOMEMLIMIT, and singleflight caching. - Use Case: A service shows p99 latency of 2s with only 5% CPU usage. The Skill directs you to fgprof for off-CPU wait time, identifies blocked goroutines on network I/O, then tunes the HTTP transport connection pool. ## Quick Start Ask the agent to review this Go package for performance anti-patterns and suggest profile-driven 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 service?▼

Profile first with pprof or fgprof before changing code, since intuition about bottlenecks is wrong most of the time. Then write an atomic benchmark, measure a baseline with -benchmem -count=6, apply one optimization at a time, and confirm with benchstat.

How do I reduce memory 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, and avoid interface boxing with generics or typed parameters. Check escape analysis with go build -gcflags="-m".

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 wait time. Low CPU with high latency means goroutines are blocked on I/O such as network or database calls, which standard CPU profiling does not capture.

Does Go map memory shrink after deleting keys?▼

No. 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 buckets be garbage collected.

When should I use sync.Pool in Go?▼

Use sync.Pool for frequently allocated, short-lived objects in hot paths like HTTP handlers. Reset state before Put, return copies rather than pooled buffers, and avoid pooling objects larger than about 32KB.

Why is my Go struct using more memory than expected?▼

Field ordering causes padding bytes for alignment. Reorder fields from largest to smallest (int64 first, bools last) and run the fieldalignment tool to detect wasted space automatically.