go-optimization

Identify and optimize Go performance bottlenecks using pprof profiling and benchmarking.

8|2|Updated Oct 17, 2025
One-click install
npx skills add https://github.com/geoffjay/claude-plugins --skill go-optimization
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-optimization
Source: https://github.com/geoffjay/claude-plugins/tree/main/plugins/golang-development/skills/go-optimization
Command: npx skills add https://github.com/geoffjay/claude-plugins --skill go-optimization

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go applications can suffer from performance bottlenecks, high memory consumption, and inefficient resource usage if not properly optimized. This Skill provides expert guidance on identifying and resolving these issues, ensuring your applications run at peak efficiency.

Core Features & Use Cases

  • Profiling: Master techniques for CPU, memory, and HTTP profiling using pprof, and execution tracing with go tool trace to pinpoint performance hotspots.
  • Memory Optimization: Implement strategies like escape analysis, pre-allocation, sync.Pool for object reuse, and zero-copy techniques to minimize memory footprint.
  • Concurrency Optimization: Reduce lock contention with sync.RWMutex or sharded locks, optimize channel buffering, and leverage atomic operations for efficient parallel processing.
  • Use Case: A Go developer notices their microservice has high latency and memory spikes under load. This Skill guides them through using pprof to pinpoint CPU hotspots and memory allocations, then provides code examples for pre-allocating slices and using sync.Pool to significantly improve performance and reduce resource footprint.

Quick Start

// Start CPU profiling import ( "os" "runtime/pprof" )

func main() { f, _ := os.Create("cpu.prof") defer f.Close() pprof.StartCPUProfile(f) defer pprof.StopCPUProfile()

// Your application code
runApplication()

}

// Analyze with: go tool pprof cpu.prof

Frequently Asked Questions about go-optimization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I profile CPU and memory bottlenecks in my Go application?

Use Go's `pprof` tool to profile CPU and memory performance. Import `runtime/pprof`, start profiling with `pprof.StartCPUProfile()`, run your code, then analyze results with `go tool pprof`. This identifies hotspots and allocations causing slowdowns.

What's the best way to reduce memory usage in Go applications?

Apply escape analysis, pre-allocate slices, use `sync.Pool` for object reuse, and employ zero-copy techniques. These strategies minimize heap allocations and garbage collection pressure, directly lowering memory footprint under load.

How can I optimize concurrency performance in Go?

Reduce lock contention using `sync.RWMutex` or sharded locks, optimize channel buffering, and leverage atomic operations. These techniques improve parallel processing efficiency and reduce synchronization overhead in concurrent workloads.

When should I use execution tracing versus CPU profiling in Go?

Use CPU profiling with `pprof` to identify which functions consume most resources. Use `go tool trace` for execution tracing to visualize goroutine scheduling, lock contention, and GC events. Combine both for comprehensive performance analysis.

Can I optimize hot paths in microservices without rewriting core logic?

Yes. Profile with `pprof` to pinpoint exact bottlenecks, then apply targeted optimizations: pre-allocate buffers, cache allocations with `sync.Pool`, and tune channel sizes. This delivers measurable latency and memory improvements with minimal code changes.

What's required before starting Go performance optimization work?

Gather reproducible profiling outputs using `pprof` or `go tool trace`, establish baseline benchmarks with `go test -bench`, and identify your performance target. Clear metrics and reproducibility are essential for validating optimization impact.