Go performance optimization - profiling, benchmarks, memory management
View on GitHubpluginagentmarketplace/custom-plugin-go
go-development-assistant
January 21, 2026
Select agents to install to:
npx add-skill https://github.com/pluginagentmarketplace/custom-plugin-go/blob/main/skills/go-performance/SKILL.md -a claude-code --skill go-performanceInstallation paths:
.claude/skills/go-performance/# Go Performance Skill
Optimize Go application performance with profiling and best practices.
## Overview
Comprehensive performance optimization including CPU/memory profiling, benchmarking, and common optimization patterns.
## Parameters
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| profile_type | string | yes | - | Type: "cpu", "memory", "goroutine", "block" |
| duration | string | no | "30s" | Profile duration |
## Core Topics
### pprof Setup
```go
import (
"net/http"
_ "net/http/pprof"
)
func main() {
// Start pprof server
go func() {
http.ListenAndServe("localhost:6060", nil)
}()
// Your application
runApp()
}
```
### CPU Profiling
```bash
# Collect 30s CPU profile
go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30
# Interactive commands
(pprof) top 10 # Top 10 CPU consumers
(pprof) list funcName # Source view
(pprof) web # Open in browser
(pprof) svg > cpu.svg # Export SVG
```
### Memory Profiling
```bash
# Heap profile
go tool pprof http://localhost:6060/debug/pprof/heap
# Allocs since start
go tool pprof http://localhost:6060/debug/pprof/allocs
(pprof) top --cum # By cumulative allocations
(pprof) list funcName # Where allocations happen
```
### Benchmarking
```go
func BenchmarkProcess(b *testing.B) {
data := setupData()
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
Process(data)
}
}
func BenchmarkProcess_Parallel(b *testing.B) {
data := setupData()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
Process(data)
}
})
}
```
```bash
# Run benchmarks
go test -bench=. -benchmem ./...
# Compare benchmarks
go test -bench=. -count=5 > old.txt
# make changes
go test -bench=. -count=5 > new.txt
benchstat old.txt new.txt
```
### Memory Optimization
```go
// Preallocate slices
func ProcessItems(items []Item) []Resu