go-performance
Skill1 starsChanged 5 months agoMITView on GitHub
Go performance analysis: memory allocation, CPU bottlenecks, concurrency contention, struct alignment, escape analysis, and benchmarking patterns. Use this skill whenever writing performance-sensitive Go code, reviewing Go code for efficiency, discussing allocations or GC pressure, benchmarking, profiling with pprof, or optimizing hot paths. Also trigger when the user mentions sync.Pool, atomic operations, pre-allocation, or escape analysis — even without saying "performance."
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 23
Always ask the user to validate results — if they look too good, they probably are.
- Very specific: line 33
Every service must expose pprof.
- Very specific: line 66
Use bytes.Clone(buf.Bytes()) when you need to retain data after the buffer is returned to the pool.
- Very specific: line 124
Use the fieldalignment tool to detect suboptimal ordering.
- Distinctive: line 132
Don't return pointers to small, short-lived structs.
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Go Performance
Performance is cost in cloud, experience on user-facing paths. Never optimize without measurement.
Workflow
- Establish a benchmark baseline (see
go-testingfor benchmark patterns). - Implement fixes.
- Compare with
benchstat baseline.txt optimized.txt. - Always ask the user to validate results — if they look too good, they probably are.
Prioritize: hot paths > allocation-heavy code > concurrency contention > stylistic.
Rules
1. Expose pprof
Every service must expose pprof. Import _ "net/http/pprof" and run go http.ListenAndServe(":6060", nil) alongside the app.
| Endpoint | Shows |
/debug/pprof/profile | CPU profile |
/debug/pprof/heap | Live heap allocations |
/debug/pprof/allocs | Cumulative allocation counts |
/debug/pprof/goroutine | Goroutine stacks |
/debug/pprof/mutex | Mutex contention |
/debug/pprof/block | Blocking operations |
go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30
go tool pprof http://localhost:6060/debug/pprof/heap2. sync.Pool — Reuse Temporary Buffers
Reuse buffers on high-frequency paths to relieve GC.
var bufPool = sync.Pool{New: func() any { return new(bytes.Buffer) }}
func handleRequest(w http.ResponseWriter, r *http.Request) {
buf := bufPool.Get().(*bytes.Buffer)
defer func() { buf.Reset(); bufPool.Put(buf) }()
buf.ReadFrom(r.Body)
process(buf.Bytes())
}NEVER pool strings.Builder when returning b.String() — String() shares the builder's internal buffer (no copy). Resetting the builder corrupts the string the previous caller still holds. Use bytes.Buffer and consume buf.Bytes() before reset.
Use bytes.Clone(buf.Bytes()) when you need to retain data after the buffer is returned to the pool.
3. Pre-allocate Slices and Maps
Known size → pre-allocate. Avoids runtime reallocation and memory copying.
// ❌
var result []int
for _, v := range input {
result = append(result, v*2)
}
// ✅
result := make([]int, 0, len(input))4. strings.Builder for Concatenation
Strings are immutable. + in a loop creates a new string per iteration.
var b strings.Builder
b.Grow(expectedTotalLength)
for _, word := range words {
b.WriteString(word)
}5. strconv over fmt
fmt uses reflection. For basic type conversions, use strconv.
s := strconv.Itoa(42) // not fmt.Sprintf("%d", 42)
s := strconv.FormatFloat(f, 'f', 2, 64) // not fmt.Sprintf("%.2f", f)6. Struct Field Alignment
Order fields largest → smallest to minimize padding.
// ❌ 24 bytes (padding waste)
type User struct {
IsAdmin bool // 1 + 7 padding
ID int64 // 8
Age int8 // 1 + 7 padding
}
// ✅ 16 bytes
type User struct {
ID int64 // 8
IsAdmin bool // 1
Age int8 // 1 + 6 padding
}Use the fieldalignment tool to detect suboptimal ordering.
7. Prefer strings/bytes over regexp
regexp is safe but slow. Use strings functions for simple matching. If regex is unavoidable, compile once at package level with regexp.MustCompile.
8. Escape Analysis — Keep Allocations on the Stack
Don't return pointers to small, short-lived structs. For slices, use the append pattern — pass a destination slice so the caller manages memory.
// ❌ forces heap allocation every call
func (m *IntMap) Convert() []int {
result := make([]int, 0, len(m.data))
for _, v := range m.data {
result = append(result, v)
}
return result
}
// ✅ caller controls allocation
func (m *IntMap) Convert(dst []int) []int {
for _, v := range m.data {
dst = append(dst, v)
}
return dst
}9. Concrete Returns over Interface Returns
Accept interfaces, return concrete types. Returning an interface forces a wrapping allocation. (See also go-style interface design rules.)
10. Atomics and RWMutex for Contention
sync.Mutex serializes goroutines. Use sync/atomic for counters, sync.RWMutex for read-heavy data.
// ❌ mutex for a counter
type Counter struct {
mu sync.Mutex
v int64
}
// ✅ atomic
type Counter struct {
v atomic.Int64
}
func (c *Counter) Add() { c.v.Add(1) }11. defer on Hot Paths
Go 1.22+ significantly reduced defer overhead. In most code, use defer freely (as go-style recommends). Only consider manual unlock/close on benchmarked hot paths where profiling shows defer as a measurable contributor — this is rare post-1.22.
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- Rain-kl/OpenFlare★ 296same name
- h0rn3t/golang-skills★ 7same name
- Dankosik/golang-backend-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository17 other files it gives its agents.
- autonomous-orchestrationSkill
- blast-radiusSkill
- Codebase AnalyzerSkill
- Codebase LocatorSkill
- coding-styleSkill
- conventional-commitSkill
- design-rubricSkill
- diagnoseSkill
- go-instrumentationSkill
- go-styleSkill
- go-testingSkill
- grill-meSkill
- grill-with-docsSkill
- improve-go-architectureSkill
- tddSkill
- to-issuesSkill
- to-prdSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

