mcpbeat Sign in

Go Performance Agent Skill

by cxuu

Use when optimizing Go code, investigating slow performance, or writing performance-critical sections. Also use when a user mentions slow Go code, string concatenation in loops, or asks about benchmarking, even if the user doesn't explicitly mention performance patterns. Does not cover concurrent performance patterns (see go-concurrency).

6k tokens
context cost
the whole folder, loaded on every use
4
files
ships runnable scripts
0
copies elsewhere
how many repositories repackaged it
136
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/cxuu/golang-skills --skill go-performance

The instruction itself

12 sections, as written by the author

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()

| Approach | Speed | Allocations |

|----------|-------|-------------|

| fmt.Sprint | 143 ns/op | 2 allocs/op |

| strconv.Itoa | 64.2 ns/op | 1 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
}

Prefer Specifying Container Capacity

Specify container capacity where possible to allocate memory up front. This minimizes subsequent allocations from copying and resizing as elements are added.

Map Capacity Hints

Provide capacity hints when initializing maps with make():

m := make(map[string]os.DirEntry, len(files))

Note: Unlike slices, map capacity hints do not guarantee complete preemptive allocation—they approximate the number of hashmap buckets required.

Slice Capacity

Provide capacity hints when initializing slices with make(), particularly when appending:

data := make([]int, 0, size)

Unlike maps, slice capacity is not a hint—the compiler allocates exactly that much memory. Subsequent append() operations incur zero allocations until capacity is reached.

| Approach | Time (100M iterations) |

|----------|------------------------|

| No capacity | 2.48s |

| With capacity | 0.21s |

The capacity version is ~12x faster due to zero reallocations during append.


Pass Values

Don't pass pointers as function arguments just to save a few bytes. If a function refers to its argument x only as *x throughout, then the argument shouldn't be a pointer.

func process(s string) { // not *string — strings are small fixed-size headers
    fmt.Println(s)
}

Common pass-by-value types: string, io.Reader, small structs.

Exceptions:

  • Large structs where copying is expensive
  • Small structs that might grow in the future

String Concatenation

Choose the right strategy based on complexity:

| Method | Best For |

|--------|----------|

| + | Few strings, simple concat |

| fmt.Sprintf | Formatted output with mixed types |

| strings.Builder | Loop/piecemeal construction |

| strings.Join | Joining a slice |

| Backtick literal | Constant multi-line text |


Benchmarking and Profiling

Always measure before and after optimizing. Use Go's built-in benchmark framework and profiling tools.

go test -bench=. -benchmem -count=10 ./...

> Validation: After applying optimizations, run bash scripts/bench-compare.sh to measure the actual impact. Only keep optimizations with measurable improvement.


Quick Reference

| Pattern | Bad | Good | Improvement |

|---------|-----|------|-------------|

| Int to string | fmt.Sprint(n) | strconv.Itoa(n) | ~2x faster |

| Repeated []byte | []byte("str") in loop | Convert once outside | ~7x faster |

| Map initialization | make(map[K]V) | make(map[K]V, size) | Fewer allocs |

| Slice initialization | make([]T, 0) | make([]T, 0, cap) | ~12x faster |

| Small fixed-size args | *string, *io.Reader | string, io.Reader | No indirection |

| Simple string join | s1 + " " + s2 | (already good) | Use + for few strings |

| Loop string build | Repeated += | strings.Builder | O(n) vs O(n²) |


  • Data structures: See go-data-structures when choosing between slices, maps, and arrays, or understanding allocation semantics
  • Declaration patterns: See go-declarations when using make with capacity hints or initializing maps and slices
  • Concurrency: See go-concurrency when parallelizing work across goroutines or using sync.Pool for buffer reuse
  • Style principles: See go-style-core when deciding whether an optimization is worth the readability cost

Other skills for the same job

different authors, same section of the catalogue
Hf Release Notes
by huggingface
vendor

Generate Hugging Face Hub (huggingface_hub) release notes from cached PR JSON files. Use when asked to draft release notes from PR files.

4k tokens
Earth2studio Discover
by NVIDIA
vendor

> Find Earth2Studio models, data sources, and examples for a weather/climate use case. Do NOT use for writing inference code, downloading data, or installation.

7k tokens
Earth2studio Install
by NVIDIA
vendor

> Guide installing Earth2Studio via uv or pip, selecting model extras, and configuring the environment. Do NOT use for writing inference code, choosing models, or PhysicsNeMo questions.

6k tokens
Natural Language
by dpearson2699

Tokenize, tag, and analyze natural language text using Apple's NaturalLanguage framework and translate between languages with the Translation framework. Use when adding language identification, sentiment analysis, named entity recognition, part-of-speech tagging, text embeddings, or in-app translation to iOS/macOS/visionOS apps.

7k tokens
Legal AI Model Router Stephane Boghossian
by lawve-ai

Routes any legal task to the right LLM, like OpenRouter but for legal work and grounded in benchmarks instead of brand loyalty. Built from mid-2026 legal evals (legalbenchmarks.ai, Vals AI × Stanford LegalBench across 124 models, Harvey's Legal Agent Benchmark, the Atticus Project's CUAD/MAUD/ACORD) plus translation evidence (WMT25, SwiLTra-Bench, ArabLegalEval). Covers five verticals: contract drafting, info extraction, legal research, contract review, and legal translation (including Arabic/MENA). Each asks up to four questions (cost, speed, accuracy/stakes, privacy/jurisdiction/language), then returns a primary model, a fallback, what to avoid, and what a human must verify. Core principle: capability is not controllability, so every route ends with a verification step. Not legal advice; a lawyer owns the output.

20k tokens
Regulatory Deal Card Generator Patrick Munro
by lawve-ai

Generates standalone interactive HTML "deal cards" that translate complex regulations into negotiation-ready reference tools, systematically distinguishing mandatory obligations from negotiable implementation choices. Use when the user needs an interactive regulatory guide for (1) contract negotiation support, (2) client education or internal training, (3) regulatory briefings for commercial stakeholders, or (4) structured comparison between required and flexible compliance paths. Primary focus on EU digital regulation (Data Act, AI Act, CRA, DORA, NIS2, GDPR) but the structural pattern transfers to any regulation where separating hard obligations from implementation choice is the point. Supports bilingual output where the jurisdiction calls for it.

15k tokens
Route Contract Drafting
by lawve-ai

> Pick the right LLM for CONTRACT DRAFTING — generating, redlining, or rewriting contract language from instructions. Vendor-neutral routing grounded in mid-2026 legal benchmarks (legalbenchmarks.ai Contract Drafting). Asks up to 4 quick questions (cost, speed, accuracy/ stakes, privacy/jurisdiction/language), then recommends a primary model + fallback + what to avoid + what a human must verify. Use when someone asks "which model should I use to draft this clause/agreement", "best AI for drafting contracts", "route this drafting task", or is about to generate/redline contract text and hasn't fixed a model.

3k tokens
Status Report Drafter Scott Margetts
by lawve-ai

Draft matter status reports from emails, call notes, and updates. Internal and client-facing formats, RAG logic, variance commentary, escalation flags. Use when asked to draft a status report, write a project update, summarise matter progress, prepare a client report, create a weekly or monthly update, convert emails into a status summary, or produce any kind of matter reporting. Also triggers when the user pastes email threads and asks what the status is, or needs to turn internal updates into client-facing reports.

11k tokens

How to use it

Copy the folder

Take cxuu/go-performance from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.