golang-performance

Profile Go code with pprof and benchmarks to identify and fix performance bottlenecks.

2|Updated Mar 13, 2023
One-click install
npx skills add https://github.com/haipham22/golang-sample --skill golang-performance-haipham22
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-performance
Source: https://github.com/haipham22/golang-sample/tree/main/.agents/skills/golang-performance
Command: npx skills add https://github.com/haipham22/golang-sample --skill golang-performance-haipham22

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) and assets (resource) components.

What problem does it solve?

This Skill helps you find and fix Go performance bottlenecks without guessing, so you can improve latency, throughput, memory use, and CPU efficiency in a disciplined way.

Core Features & Use Cases

  • Profile-first optimization: Choose the right diagnostic tool before changing code, including pprof, fgprof, tracing, and benchmark-driven analysis.
  • Iterative benchmarking workflow: Measure a baseline, apply one optimization at a time, and verify gains with statistical comparison.
  • Hot-path improvements: Apply proven patterns for allocations, slice reuse, map access, error handling, interface boxing, inlining, cache locality, GC tuning, and I/O behavior.
  • Use Case: A Go API is slow under load, and you need to determine whether the real issue is database wait time, excess allocations, a bad data layout, or an inefficient loop.

Quick Start

Use the golang-performance skill to profile this Go codebase, identify the most likely bottleneck, and recommend one benchmarked optimization to test next.

Frequently Asked Questions about golang-performance

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

FAQPage Schema
How do I find and fix Go performance bottlenecks in a slow API?

Profile Go performance bottlenecks using pprof or fgprof to identify whether latency stems from database wait time, excess allocations, or bad data layout, then apply one targeted optimization and verify gains with benchstat.

What is the best way to reduce memory allocations on a Go hot path?

Reducing allocations on a Go hot path requires profiling to confirm the bottleneck, then applying proven patterns like slice reuse, avoiding interface boxing, and improving cache locality, validated through iterative benchmarking.

How do I benchmark a Go optimization to ensure it actually improves performance?

Benchmark a Go optimization by measuring a baseline, applying one change at a time, and verifying gains with statistical comparison using benchstat to ensure disciplined, measurable performance improvement.

When should I tune the Go garbage collector for better latency?

Tune the Go garbage collector when profiling with pprof indicates GC pressure is the primary bottleneck, applying runtime tuning and concurrency-aware optimization patterns to improve latency and CPU efficiency.

Does this profiling-driven optimization approach work for production Go workloads?

Profiling-driven optimization applies to production Go workloads where latency, memory, CPU, GC, or I/O behavior must improve, using disciplined measurement with pprof, tracing, and benchmark-driven analysis.

Why is my Go service slow under load and how do I diagnose it?

Diagnose a slow Go service under load by profiling to determine the real bottleneck, checking for database wait time, excess allocations, inefficient loops, or bad data layout before changing code.