Skip to content
Agentmart
Submit a tool

go-performance

Profile and optimize Go CPU, allocations, GC, concurrency, and I/O with benchmarks and pprof.

Skill by caarlos0

IndexedMIT★ 224
Write a review

Chalk Labs

Need help deploying go-performance?

Chalk Labs sets up agents like this inside real teams: connected to your tools, tested on your data, with a human in the loop where it matters.

Book a call

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/caarlos0-go-performance

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Profile and optimize Go CPU, allocations, GC, concurrency, and I/O with benchmarks and pprof.

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/go-performance

What's inside

Skill name
go-performance
Description
Profile and optimize Go CPU, allocations, GC, concurrency, and I/O with benchmarks and pprof.
License
MIT
Instructions
152 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# Go Performance

Profile before optimizing. Pin the Go version, `GOMAXPROCS`, input, and
benchmark flags. Change one measured bottleneck and compare with `benchstat`.

## Benchmarks

Benchmark production code with `testing.B`. Report allocations and throughput
where relevant:

```go
func BenchmarkEncode(b *testing.B) {
	b.ReportAllocs()
	b.SetBytes(int64(len(input)))
	for b.Loop() {
		Encode(input)
	}
}
```

Use `b.RunParallel` only when contention or scaling is the behavior under test.
Collect multiple samples:

```bash
go test -run='^$' -bench=BenchmarkEncode -benchmem -count=10 ./pkg > old.txt
go test -run='^$' -bench=BenchmarkEncode -benchmem -count=10 ./pkg > new.txt
benchstat old.txt new.txt
```

Use realistic sizes and distributions. Include `benchstat` output with a
performance change; a single `ns/op` result is not evidence.

## Profiles and trace

From tests:

```bash
go test -bench=BenchmarkEncode \
  -cpuprofile=cpu.prof -memprofile=heap.prof \
  -blockprofile=block.prof -mutexprofile=mutex.prof
go tool pprof -http=:8080 cpu.prof
go tool pprof -top -cum -alloc_objects heap.prof
```

For services, expose `net/http/pprof` only on an authenticated internal
listener. Use:

- CPU profile for sampled on-CPU hot paths.
- `allocs` for allocation sites and `heap` for live objects.
- block and mutex profiles for contention.
- goroutine profiles for growth and stuck stacks.
- `go tool trace` for scheduler latency, goroutine transitions, syscalls, GC,
  and network blocking that sampling profiles do not explain.

## Escapes, inlining, and allocations

```bash
go build -gcflags='-m=2' ./pkg/...
```

Escape and inlining diagnostics are leads. Confirm the allocation or call site
in a benchmark or profile before changing ownership.

- Pre-size slices and maps when the size is known:
  `make([]T, 0, n)` and `make(map[K]V, n)`.
- Reuse slice capacity with `s = s[:0]` only when retained backing arrays do not
  pin excessive memory.
- Use `strings.Builder` for strings and `bytes.Buffer` for bytes when repeated
  appends are measured. Do not copy a non-zero Builder; call `Reset` before
  reuse.
- Prefer `strconv.Append*` or `Format*` over `fmt.Sprintf` in formatting hot
  paths.
- Interface conversions and interface calls can cause escapes or prevent
  inlining and devirtualization. They do not always allocate; verify with
  `-gcflags=-m=2` and `-benchmem`.
- Generics do not guarantee faster code. Compare generated code and benchmarks
  before replacing an interface API.

## Pools and memory

`sync.Pool` is for temporary reusable objects that may be discarded at any
time. It provides no retention guarantee. Reset objects before `Put`, validate
state after `Get`, and benchmark pool contention plus retained capacity.

Use heap profiles to distinguish allocation rate from live heap. A large
`alloc_space` profile with a small `inuse_space` profile indicates churn, not a
leak. A goroutine retaining a reference can pin a large object graph.

Tune `GOGC` or `GOMEMLIMIT` only after allocation and GC profiles identify the
trade-off. `GOMEMLIMIT` is a soft runtime memory limit, not an RSS cap.

## Concurrency

- Use block and mutex profiles before replacing locks with channels, atomics,
  sharding, or lock-free structures.
- Use atomics only for small independent state with documented memory-ordering
  invariants.
- Bound goroutine fan-out and queue capacity. Every goroutine needs an exit
  through context cancellation, channel closure, or owned lifecycle.
- Investigate rising goroutine counts with two goroutine profiles under stable
  load; compare which stacks accumulate.
- Avoid holding locks across I/O or callbacks. Keep critical sections small
  without splitting invariants.
- Treat cache-line padding and false-sharing fixes as hardware-specific
  hypotheses; prove them with contention benchmarks.

Invoke `runtime-process-debugging` for child processes, pipes, shutdown, or
scheduler/lifecycle stalls.

## I/O and serialization

Use `bufio.Reader`/`Writer` for repeated small operations and batch small writes.
Reuse byte buffers where ownership is clear. Preserve partial-write handling,
flush errors, EOF, deadlines, cancellation, and ordering.

`encoding/json`, reflection, and struct-tag processing can be hot in
serialization-heavy programs. Profile before adding generated codecs or a
dependency; include compatibility, escaping, number handling, and error behavior
in comparisons.

From caarlos0/dotfiles, MIT.

More from caarlos0/dotfiles

Signals

Stars
224
Forks
12
Open issues
0
Last commit (this folder)
Oct 20, 2026 (10 days ago)
Last release
Oct 1, 2026 (29 days ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from caarlos0

Done for you

Rather not set it up yourself?

Chalk Labs scopes, builds and runs agents for your team: the task audit, the eval harness, the integrations and the weekly ops report. Fixed scope, priced before we start.

See how we build AI agents →Read the case studies

Chalk Labs is a two-founder AI and growth studio. We build AI agents, CRMs and MVPs for Web3 and AI companies, and have shipped 50+ product and token launches.

launches shipped
50+
launches shipped
media placements
500+
media placements
founders on every account
2
founders on every account

Press we've placed: Forbes · CoinDesk · Decrypt · Cointelegraph · The Block

Rahil Jain, Co-founder, Chalk Labs. Ex-Goldman Sachs engineer. You talk to the person who builds it.

Get go-performance running in your business

Tell us what you want to automate. A founder replies within one working day with a plan, not a pitch deck.

Goes to the Chalk Labs founders, not the newsletter. Privacy

Need help deploying go-performance?

CallGet help
Cite this page

go-performance skill. Agent Mart. https://agentmart.dev/skills/caarlos0-go-performance (last updated 2026-10-24)