cxuu avatar

Go Performance

Performance patterns for Go hot paths, covering conversions, allocation, string building, and benchmarking.

CCM score
63 of 100
skills.sh installs
1.4K
GitHub stars
197
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers strconv over fmt, repeated byte conversions, container capacity hints, pass-by-value, and string concatenation strategy
  • Includes scripts/bench-compare.sh for comparing benchmark runs and saving baselines, plus references on benchstat, pprof, and string optimization
  • Enforces measuring before and after each change, keeping only optimizations that show a measurable improvement
  • Designed for targeted tuning of hot paths in Go code, with concurrency patterns handled by go-concurrency

Install

$ npx -y skills add cxuu/golang-skills --skill go-performance -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Go Performance Patterns

Resource Routing

  • scripts/bench-compare.sh - Run when comparing benchmark results, saving baselines, or producing JSON benchmark metadata.
  • references/BENCHMARKS.md - Read when writing benchmarks, using benchstat, or profiling with pprof.
  • references/STRING-OPTIMIZATION.md - Read when optimizing string conversion, concatenation, or byte/string boundaries.

Performance-specific guidelines apply only to the hot path. Don't prematurely optimize—focus these patterns where they matter most.


Prefer strconv over fmt

When converting primitives to/from strings, strconv is faster than fmt:

s := strconv.Itoa(rand.Int()) // ~2x faster than fmt.Sprint()
ApproachSpeedAllocations
fmt.Sprint143 ns/op2 allocs/op
strconv.Itoa64.2 ns/op1 allocs/op

Avoid Repeated String-to-Byte Conversions

Convert a fixed string to []byte once outside the loop:

data := []byte("Hello world")
for b.Loop() { // Go 1.24+; use b.N loops only for older Go
    w.Write(data) // ~7x faster than []byte("...") each iteration
}

Details

Repository
github.com/cxuu/golang-skills
Categories
Go, Debugging
First seen
May 16, 2026

More from cxuu/golang-skills

All 20

Similar to Go Performance

More Go