Logo di Go Performance Review

Go Performance Review

Community
eduardo-sl
go-performance-review

Detect performance anti-patterns and apply optimization techniques in Go. Covers allocations, benchmarks and benchstat, pprof and traces, GC and GOMEMLIMIT tuning, PGO, and HTTP client reuse. Use when checking performance, finding slow code, reducing allocations, profiling, or reviewing hot paths. Trigger examples: "check performance", "find slow code", "reduce allocations", "benchmark this", "profile", "optimize Go code". Not for: concurrency correctness (go-concurrency-review), general style (go-coding-standards).

Add to TypingMind

Panoramica

Pubblicato daeduardo-sl
Repositorygo-agent-skills
Nome della skillgo-performance-review
Stelle
86
Fork
11
File inclusi
5
LicenzaMIT
Link
  • Istruzioni in Markdown

    Un file SKILL.md che il modello carica quando serve, consumando token solo quando una richiesta è effettivamente pertinente.

  • Funziona con qualsiasi LLM

    Le skill IA sono in semplice Markdown, non in codice specifico di un fornitore, quindi funzionano con GPT, Claude, Gemini, Grok o un modello locale.

  • File inclusi: 5

    Script, template e riferimenti che il modello può leggere mentre lavora. I file sono di sola lettura e non vengono mai eseguiti.

  • Open source

    Pubblicata da eduardo-sl su GitHub. Leggi i sorgenti prima di installarla.

Installazione

Installa la skill IA Go Performance Review in TypingMind per usarla con qualsiasi LLM, oppure copiala in un altro agente in grado di leggere SKILL.md.

1

Installa in TypingMind

TypingMind installa una skill direttamente dalla sua cartella GitHub: legge SKILL.md, raccoglie i file delle risorse e salva il risultato in locale.

  1. Apri l'app e vai su Plugin → Skill.
  2. Scegli "Installa da GitHub".
  3. Incolla l'URL della cartella della skill riportato qui sotto e conferma.
    https://github.com/eduardo-sl/go-agent-skills/tree/main/skills/(safety)/go-performance-review
  4. Attiva la skill in ogni chat in cui vuoi averla a disposizione.
Plugin → Skill → Aggiungi skill → Da URL GitHub, poi incolla l'URL della cartella e premi Continua.

Usala in TypingMind

Attiva Go Performance Review in qualsiasi chat di TypingMind e al resto pensa il modello. Il nome e la descrizione della skill sono nel prompt di sistema e, non appena arriva una richiesta pertinente, il modello carica da solo le istruzioni complete: non devi mai richiamarla manualmente e non consuma token finché non viene effettivamente usata.

Il modello carica automaticamente Go Performance Review non appena riceve una richiesta pertinente.

Funziona con qualsiasi modello IA

Le skill IA sono semplici istruzioni in Markdown, non codice specifico di un fornitore, quindi Go Performance Review non è vincolata al modello per cui è stata scritta. Installala una sola volta in TypingMind e usala con GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama o un modello locale che esegui tu, sempre con le tue chiavi API.

  • Caricata solo quando serve

    Il prompt di sistema contiene solo il nome e la descrizione. Le istruzioni vengono recuperate alla prima richiesta pertinente, quindi una skill inutilizzata non costa nulla.

  • Cambia modello durante la chat

    Poiché la skill è composta da istruzioni e non da codice, continua a funzionare anche se cambi modello: il nuovo modello legge lo stesso file SKILL.md.

Istruzioni della skill

Questo è il contenuto di SKILL.md che il modello carica. Leggilo prima dell'installazione: una skill è un insieme di istruzioni che il tuo modello seguirà.

Go Performance Review

Profile first, optimize second. Never optimize without a benchmark proving the problem.

Detailed reference material, loaded on demand:

  • references/benchmarking.md — benchmark shape, running, reading benchstat, comparing variants, commit format, CI regression checks.
  • references/memory-and-io.md — allocation, hot-path and map examples, retention, struct layout, false sharing, HTTP clients, streaming, batching.
  • references/profiling.md — which profile for which symptom, capture commands, reading pprof, compiler diagnostics, traces, flight recorder.
  • references/runtime-tuning.md — GOGC/GOMEMLIMIT, reading gctrace, GOMAXPROCS in containers, PGO.
  • references/logging.md — slog vs zap/zerolog decision table, slog with a zap backend, logging anti-patterns in hot paths.

Read a reference file only when the summary below is not enough.

Operating Modes

  • Architecture review (a package or service): look for structural costs — no connection reuse, unbounded goroutines, N+1 queries, the wrong data structure, per-request work that could be done once. Run separate passes for allocation and layout, I/O and concurrency, and algorithms and caching; give each to a parallel sub-agent if the environment supports it.
  • Hot-path review (one function the caller names): read it alongside its profile, sequentially.
  • Optimize (a bottleneck is known): follow the cycle below, one change at a time.

The Optimization Cycle

  1. Name the metric and the target — p99 latency, throughput, allocs/op, RSS. Without a target, optimization never ends.
  2. Rule out external time first. Goroutines parked in net.(*conn).Read or database/sql, or a trace dominated by one upstream span, mean the fix is elsewhere (go-database, go-observability).
  3. Benchmark the isolated path and save the baseline: go test -run '^$' -bench Name -benchmem -count=10 | tee old.txt.
  4. Profile to find the cause — see Profiling below.
  5. Change one thing, with a comment saying why it is faster.
  6. Re-measure on the same machine and toolchain; keep the change only if benchstat old.txt new.txt shows a significant difference.
  7. Put the benchstat table in the commit body (perf(scope): ...).

1. Allocation Reduction

  • strconv instead of fmt.Sprintf for single values.
  • strings.Builder (with Grow when the size is known) instead of += in loops.
  • Preallocate slices and maps when the size is known or bounded: make([]T, 0, n), make(map[K]V, n).
  • Reuse buffers on a proven hot path with sync.Pool — reset on get, size-cap on put (the concurrency skill has the pattern).
  • Watch for hidden allocations: values stored in interfaces, closures capturing variables, []byte(s)/string(b) conversions, and anything go build -gcflags=-m reports as escapes to heap.

2. Hot Path Optimizations

  • Concrete types in tight loops — interface method calls block inlining and boxing allocates.
  • No reflect on hot paths; generate code instead (stringer, protobuf).
  • Contiguous data beats pointer chasing: []Point over []*Point, and a struct of slices when a loop touches one field of many records.

3. Map Performance

  • Capacity hints when the size is known.
  • sync.Map only for its two documented workloads; otherwise a map guarded by a mutex.
  • A small fixed key set (enum-indexed) is faster as an array or slice.

Examples for sections 1-3: references/memory-and-io.md.

4. Benchmarking

go
func BenchmarkParse(b *testing.B) {
    input := makeInput(4 << 10) // setup runs once, outside the timed loop
    b.ReportAllocs()
    for b.Loop() {              // Go 1.24+: no ResetTimer, no sink variable
        Parse(input)
    }
}
  • -count=10 and benchstat, never a single run. ~ in its output means "no change", whatever the percentage says.
  • Sub-benchmarks per input size; inputs sized like production.
  • Below Go 1.24, use for range b.N with b.ResetTimer() after setup and a package-level sink.
  • Competing variants are built in parallel but benchmarked one at a time — concurrent runs contaminate each other.

Commands, reading guide and CI regression checks: references/benchmarking.md.

5. Profiling

SymptomFirst profile
High CPUCPU profile — high flat functions
GC busy, high allocation rateheap with -sample_index=alloc_objects
Memory grows over timetwo heap snapshots, go tool pprof -base
Latency high, CPU idlegoroutine dump, block/mutex profiles, a trace
Lock contentionmutex profile (runtime.SetMutexProfileFraction)
Scheduling delays, GC pausesexecution trace; flight recorder (Go 1.25+) in production
bash
go test -run '^$' -bench Name -cpuprofile cpu.out -memprofile mem.out ./pkg
go tool pprof -http=:0 cpu.out                     # flame graph
go build -gcflags='-m' ./pkg 2>&1 | grep 'escapes'  # what moves to the heap

The CPU profile only sees running goroutines: when latency is high and CPU is low, the time is waiting, and only the goroutine, block and trace views show it. Commands, reading guide, escape analysis and the flight recorder: references/profiling.md.

Importing net/http/pprof registers its handlers on http.DefaultServeMux. If the service also serves public traffic from DefaultServeMux, profiles, command line and goroutine stacks become world-readable. Always give pprof its own loopback or internal-network listener.

6. Runtime Tuning

  • In containers, set GOMEMLIMIT to ~80-90% of the memory limit and keep GOGC; the GC then works harder near the ceiling instead of the process being OOM-killed. Never GOGC=off with only a limit.
  • Go 1.25+ derives GOMAXPROCS from the cgroup CPU limit — remove automaxprocs and don't set it by hand without a measurement.
  • Commit a production CPU profile as default.pgo for PGO (Go 1.21+).
  • After a toolchain upgrade (Green Tea GC in 1.26, the 1.27 allocator), re-measure before keeping old tuning.

Detail, gctrace reading and runtime/metrics: references/runtime-tuning.md.

7. I/O and HTTP Clients

  • One http.Client per process, with a Timeout and a transport cloned from http.DefaultTransport with MaxIdleConnsPerHost raised — the default of 2 churns connections under concurrency.
  • Close every response body and read it to EOF so the connection returns to the pool.
  • Stream: decode from r.Body with a size cap instead of io.ReadAll; io.Copy for proxying; bufio for many small writes.
  • Batch round trips — rows, API calls, channel items.
  • Subslices and substrings of large buffers keep the whole buffer alive; slices.Clone/strings.Clone what you keep.

Examples, struct layout and false sharing: references/memory-and-io.md.

8. High-Throughput Logging

log/slog is the default. Switch only when a benchmark shows logging in the profile, and then keep the slog API with a faster backend (zap's zapslog handler) so callers never change. In hot loops, log progress every N items or a summary after the loop — never once per item. Decision table and examples: references/logging.md.

9. Common Anti-Patterns

Anti-PatternFix
fmt.Sprintf for simple int→stringstrconv.Itoa
String concatenation in loopstrings.Builder
Slice without preallocationmake([]T, 0, n)
Map without capacity hintmake(map[K]V, n)
regexp.Compile inside functionCompile once at package level
json.Marshal in hot pathProfile first: since Go 1.27 encoding/json runs on the faster v2 engine; code-gen (easyjson) only if JSON still dominates
Logging in tight loopBatch or sample
defer in very tight inner loopManual cleanup (rare, benchmark first)
http.Get / default client in productionShared client with Timeout and tuned transport
io.ReadAll on request or response bodiesStream with a decoder and a size cap
reflect.DeepEqual outside testsslices.Equal, maps.Equal, bytes.Equal
panic/recover as control flowReturn errors — a panic captures a stack trace

Important Caveat

Most Go code is not performance-critical. Readability and correctness ALWAYS take priority over micro-optimizations. Only apply these patterns when:

  1. A benchmark proves this code path is a bottleneck
  2. The optimization is significant (>10% improvement)
  3. The resulting code remains readable and maintainable

Premature optimization is still the root of all evil, even in Go.

File inclusi

Il modello legge questi file quando servono, mentre la skill è caricata. Sono accessibili in sola lettura e non vengono mai eseguiti.

Domande frequenti

Cosa fa la skill IA Go Performance Review?

Detect performance anti-patterns and apply optimization techniques in Go. Covers allocations, benchmarks and benchstat, pprof and traces, GC and GOMEMLIMIT tuning, PGO, and HTTP client reuse. Use when checking performance, finding slow code, reducing allocations, profiling, or reviewing hot paths. Trigger examples: "check performance", "find slow code", "reduce allocations", "benchmark this", "profile", "optimize Go code". Not for: concurrency correctness (go-concurrency-review), general style (go-coding-standards).

Perché usare Go Performance Review su TypingMind?

Perché la installi una volta e la usi con qualsiasi modello. Go Performance Review è scritta in semplice Markdown anziché in codice specifico di un fornitore, quindi la stessa skill funziona con GPT-5, Claude, Gemini, Grok o un modello locale, e puoi cambiare modello durante la chat senza che la skill smetta di funzionare. TypingMind usa le tue chiavi API, quindi paghi direttamente i fornitori anziché un abbonamento per posto utente, e le tue skill e chat restano nel tuo spazio di archiviazione.

Come installo Go Performance Review in TypingMind?

Apri Plugin → Skill → Installa da GitHub in TypingMind e incolla https://github.com/eduardo-sl/go-agent-skills/tree/main/skills/(safety)/go-performance-review. TypingMind legge il file SKILL.md, include i file associati e installa la skill, che puoi abilitare per ogni singola chat.

Quali modelli IA possono usare Go Performance Review?

Qualsiasi modello che colleghi a TypingMind. Le skill IA sono semplici istruzioni in Markdown anziché codice specifico di un fornitore, quindi GPT, Claude, Gemini, Grok e i modelli locali possono tutti caricare questa skill quando una richiesta corrisponde al suo scopo.

Quanti modelli IA posso usare con Go Performance Review?

Quanti ne vuoi. Se un modello supporta le skill, puoi usarlo con Go Performance Review: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama e molti altri, tutti su TypingMind con le tue chiavi API.

La skill IA Go Performance Review è gratuita?

Sì. È pubblicata su GitHub da eduardo-sl con licenza MIT. Paghi solo il tuo fornitore IA per i token che usi.

Cosa sono le skill IA?

Una skill IA è un pacchetto di istruzioni riutilizzabili che insegna a un modello IA come svolgere un'attività specifica. Segue il formato aperto Agent Skills: un file SKILL.md con un nome e una descrizione, più eventuali script, template o file di riferimento di cui il modello potrebbe aver bisogno. Il modello legge le istruzioni solo quando la tua richiesta corrisponde alla skill, quindi una skill installata non comporta costi finché non viene usata.

In cosa si differenziano le skill IA dai plugin o dai server MCP?

Un plugin o un server MCP fornisce a un modello nuovi strumenti da richiamare: codice che viene eseguito da qualche parte e restituisce un risultato. Una skill IA, invece, fornisce al modello conoscenze e procedure: come affrontare un'attività, quali passaggi seguire e quali caratteristiche deve avere un buon output. Le skill sono semplici istruzioni in Markdown, quindi non richiedono server, chiavi API né ambienti di esecuzione e funzionano con qualsiasi modello.

Elenco completo

Crea subito il tuo spazio di lavoro AI

Iscriviti alla nostra newsletter per ricevere aggiornamenti sulle nuove funzionalità e sulle prossime iniziative a premi 👇