- Home
- Skills
- Cxuu
- Golang Skills
- Go Performance
go-performance_skill
- HTML
1
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 cxuu/golang-skills --skill go-performance- SKILL.md4.6 KB
Overview
This skill documents Go performance patterns for hot paths, focusing on efficient string handling, type conversions, and container capacity hints. It distills practical, production-ready recommendations to reduce allocations and CPU overhead when optimizing Go code.
How this skill works
The skill highlights concrete substitutions and initialization strategies that reduce allocations and improve throughput: use strconv instead of fmt for primitive-to-string conversions, avoid repeated string-to-byte conversions by reusing slices, pre-size slices and maps with make(), and prefer passing small fixed-size values instead of pointers. Benchmarks and examples illustrate the typical speed and allocation impact of each pattern.
When to use it
- When optimizing hotspots or latency-sensitive code paths
- Before running microbenchmarks or profiling-guided optimizations
- When building high-throughput servers, parsers, or tight loops
- When reducing GC pressure and allocation churn matters
- While preparing code for production at scale
Best practices
- Measure and profile first; apply these patterns only in hot paths
- Replace fmt-based conversions with strconv for primitives
- Convert constant strings to []byte once and reuse the slice
- Initialize slices and maps with capacity hints using make()
- Pass small fixed-size values (string, interface) by value, not pointer
Example use cases
- Replace fmt.Sprint with strconv.Itoa in tight loops generating IDs
- Pre-convert static payloads to []byte to avoid per-request allocations
- Use make([]T, 0, n) when building a slice in a loop to avoid reallocations
- Create maps with make(map[K]V, len(items)) when populating from a listing
- Change function signatures from *string to string for simple read-only inputs
FAQ
Not always. They matter in hot paths or tight loops. Profile to confirm benefits before changing code.
Do map capacity hints guarantee zero resizes?
No. The map capacity hint approximates bucket needs and reduces, but does not guarantee, dynamic resizes.