Go Performance & Quality
Best practices for Go standard library usage, effective testing, and performance optimization. Covers HTTP client/server pitfalls, JSON/SQL mistakes, table-driven tests, profiling, memory allocation, CPU caches, and GC tuning.
When to Use This Skill
- Using net/http (client timeouts, connection pooling)
- Working with encoding/json, database/sql, time package
- Writing benchmarks and table-driven tests
- Profiling and optimizing Go applications
- Understanding escape analysis, inlining, false sharing
- Tuning the garbage collector
How It Works
- Identifies performance anti-patterns and stdlib misuse
- Explains production impact (memory leaks, connection exhaustion, GC pressure)
- Shows correct patterns with measurable improvements
- Covers profiling-first optimization workflow
Categories Covered
- Standard Library — HTTP timeouts, JSON errors, SQL pitfalls, time.After leaks
- Testing — table-driven tests, race detector, benchmarks, test execution modes
- Optimizations — CPU caches, false sharing, stack vs heap, GC tuning, inlining
Present Results to User
When identifying issues:
❌ Found: HTTP client with no timeout
📍 Location: client/api.go:23
⚠️ Impact: HIGH - Connections hang indefinitely in production
✅ Fix: Set Timeout on http.Client
[Show incorrect code]
[Show correct code]
[Explain why the fix matters]
Troubleshooting
Premature optimization warning:
- Profile first with
go tool pprof before applying optimizations
- These patterns prevent common footguns, not every pattern applies to every codebase
Benchmark reliability:
- Use
b.ResetTimer() after setup code
- Use
b.ReportAllocs() to track allocations
- Run with
-benchmem flag
1---2name: go-performance3description: Use this skill when optimizing Go performance, writing benchmarks, using the standard library (HTTP, JSON, SQL, time), or ensuring production-quality testing.4---56# Go Performance & Quality78Best practices for Go standard library usage, effective testing, and performance optimization. Covers HTTP client/server pitfalls, JSON/SQL mistakes, table-driven tests, profiling, memory allocation, CPU caches, and GC tuning.910## When to Use This Skill1112- Using net/http (client timeouts, connection pooling)13- Working with encoding/json, database/sql, time package14- Writing benchmarks and table-driven tests15- Profiling and optimizing Go applications16- Understanding escape analysis, inlining, false sharing17- Tuning the garbage collector1819## How It Works20211. Identifies performance anti-patterns and stdlib misuse222. Explains production impact (memory leaks, connection exhaustion, GC pressure)233. Shows correct patterns with measurable improvements244. Covers profiling-first optimization workflow2526## Categories Covered27281. **Standard Library** — HTTP timeouts, JSON errors, SQL pitfalls, time.After leaks292. **Testing** — table-driven tests, race detector, benchmarks, test execution modes303. **Optimizations** — CPU caches, false sharing, stack vs heap, GC tuning, inlining3132## Present Results to User3334When identifying issues:35```36❌ Found: HTTP client with no timeout37📍 Location: client/api.go:2338⚠️ Impact: HIGH - Connections hang indefinitely in production39✅ Fix: Set Timeout on http.Client4041[Show incorrect code]42[Show correct code]43[Explain why the fix matters]44```4546## Troubleshooting4748**Premature optimization warning:**49- Profile first with `go tool pprof` before applying optimizations50- These patterns prevent common footguns, not every pattern applies to every codebase5152**Benchmark reliability:**53- Use `b.ResetTimer()` after setup code54- Use `b.ReportAllocs()` to track allocations55- Run with `-benchmem` flag