203
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill caarlos0/dotfiles --skill go-performance- SKILL.md2.1 KB
Overview
This skill analyzes and optimizes Go program performance by guiding profiling, interpretation, and targeted fixes. It helps generate and inspect CPU, heap, and goroutine profiles, identify hotspots, and produce actionable recommendations. The focus is on measurable improvements via benchmarks and regression checks.
How this skill works
The skill identifies profile sources (files, HTTP pprof endpoints, or generates them from tests/servers) and runs go tool pprof or equivalent commands to extract hotspots, allocations, and cumulative stacks. It interprets top and cumulative outputs, flame graphs, and allocation metrics to pinpoint CPU bottlenecks, GC pressure, and potential leaks. Recommendations include code changes, benchmark-driven validation, and regression comparisons using base profiles.
When to use it
- You need to find the CPU-bound hotspots in a Go program
- Investigating memory allocations, GC pressure, or potential memory leaks
- Validating performance impact of a code change with benchmarks
- Comparing profiles to detect regressions between versions
- Exploring goroutine contention or unexpected goroutine growth
Best practices
- Always write or update a benchmark that reproduces the issue before making changes
- Collect CPU profiles for at least 30 seconds to get meaningful samples
- Capture heap profiles at two points in time to detect leaks and use -base to compare
- Start with quick wins: low-effort changes with high impact (e.g., reuse buffers, avoid allocations)
- If hotspots are in dependencies, inspect source under GOPATH or module cache and consider targeted fixes or replacements
Example use cases
- Run go test -bench=. -cpuprofile cpu.prof -memprofile mem.prof to produce profiles from benchmarks and then pprof -top -cum cpu.prof to find hotspots
- Use go tool pprof -alloc_space -top mem.prof to find functions responsible for most bytes allocated
- Compare old and new profiles with go tool pprof -base old.prof new.prof to find regressions after a change
- Expose /debug/pprof endpoints on a service and fetch profiles to analyze live behavior
FAQ
Run CPU profiles for 30+ seconds to collect representative samples; longer runs reduce noise for short-lived or bursty workloads.
How do I detect a memory leak?
Take heap profiles at two distinct times and compare them (or use -base). Persistent growth in retained bytes for the same objects indicates a leak.