go-perfbook
Thoughts on Go performance optimization
A community-written guide on making Go programs run faster, covering general optimization strategies and Go-specific profiling tools, garbage collection, algorithms, and data structures, available in four languages.
This repository is a community-written guide on how to make Go programs run faster. Go is a programming language developed by Google and is widely used for building backend services and tools. Performance optimization means identifying where a program spends unnecessary time or memory, then changing the code to fix it.
The guide is organized as a single long document (with a table of contents) split into two broad halves. The first half covers optimization ideas that apply to any programming language, such as how to think about optimization as a workflow, how to pick better algorithms, how to structure data so it is faster to access, and how to write meaningful benchmark tests. The second half focuses specifically on Go: how Go handles memory cleanup (called garbage collection), how its runtime and compiler work under the hood, how to use profiling tools to find slow spots in a running program, and when to use lower-level techniques like writing in assembly language.
There are also sections on common mistakes when using Go's standard library, how to call C code from Go (a feature called CGO), and how to think about performance at the level of an entire service rather than a single function.
The document is available in English, Chinese, Spanish, and Brazilian Portuguese. It is described as a work in progress, and contributions are welcome through the Gophers community Slack channel. The README is short; the main content lives in the linked markdown files inside the repository.
Where it fits
- Learn a systematic workflow for profiling and optimizing a slow Go service in production
- Find Go-specific performance pitfalls in standard library usage before deploying
- Study how the Go garbage collector works to reduce GC pauses in a latency-sensitive application
- Write meaningful Go benchmark tests that avoid common measurement mistakes