chao-go-perf

Diagnose and optimize Go CPU, memory, GC, and concurrency performance bottlenecks.

44|4|Updated May 26, 2026
One-click install
npx skills add https://github.com/smallnest/chao-go-perf --skill chao-go-perf-smallnest
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: chao-go-perf
Source: https://github.com/smallnest/chao-go-perf
Command: npx skills add https://github.com/smallnest/chao-go-perf --skill chao-go-perf-smallnest

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Go developers often struggle to find and fix performance bottlenecks such as CPU hotspots, excessive heap allocations, GC pressure, lock contention, and false sharing. This Skill provides a structured, measurement-first methodology grounded in authoritative sources (Dave Cheney's High Performance Go workshop, go-perfbook, Effective Go) to diagnose and resolve these issues with concrete, verifiable optimizations. ## Core Features & Use Cases - Bottleneck Diagnosis: Analyze CPU profiles, memory allocation profiles, mutex contention, and goroutine traces using pprof, trace, and flame graphs. - Memory & Compiler Optimization: Apply escape analysis, slice/map preallocation, strings.Builder, sync.Pool reuse, struct field alignment, BCE (bounds check elimination), and inlining guidance. - Concurrency & Cache Optimization: Choose between Mutex/RWMutex/atomic/sync.Map, eliminate false sharing with cache-line padding, and detect goroutine leaks. - Use Case: A service suffers high latency under load. The Skill walks you through generating a CPU profile with go test -bench=. -cpuprofile=cpu.out, identifying the hottest function in a flame graph, checking escape analysis with -gcflags="-m", applying a fix, and validating the improvement statistically with benchstat. ## Quick Start Ask the assistant to analyze your Go benchmark or pprof profile and suggest performance optimizations for the hottest code paths.

Frequently Asked Questions about chao-go-perf

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

FAQPage Schema
How do I find CPU hotspots in a Go program?

Generate a CPU profile with go test -bench=. -cpuprofile=cpu.out, then open it with go tool pprof -http=:8080 cpu.out. Use the flame graph view to find the widest functions, which consume the most CPU time.

How do I reduce memory allocations in Go?

Run go build -gcflags="-m" to inspect escape analysis, preallocate slices and maps with known capacity, use strings.Builder instead of + concatenation, and reuse temporary objects with sync.Pool. Verify improvements with -benchmem and benchstat.

When should I use sync.Pool in Go?

Use sync.Pool for high-frequency temporary objects like bytes.Buffer that are cheap to reuse. Always call Reset before putting objects back, and avoid it for stateful or long-lived objects since GC may clear pooled items.

Mutex vs RWMutex vs atomic in Go, which should I choose?

Use atomic operations for simple counters and flags, sync.Mutex for balanced read/write workloads, and sync.RWMutex when reads exceed roughly 90 percent. For high write contention, consider sharded locks to spread contention.

What is false sharing and how do I fix it in Go?

False sharing occurs when goroutines on different cores write variables sharing one 64-byte cache line, causing severe slowdowns. Fix it by padding structs with 56 bytes between hot fields so each lands on its own cache line.

Does Go PGO improve performance and how do I enable it?

PGO typically improves CPU-bound programs by 2-7 percent. Collect a representative profile, save it as default.pgo in the main package directory, and run go build; the compiler automatically applies profile-guided inlining and layout decisions.