Profile-guided optimization (PGO) in Go
Answer: Put a pprof CPU profile named default.pgo in the main package directory and go build uses it automatically.
Versions
- Go 1.20: preview.
- Go 1.21: ready for general production use.
Steps
- Collect a CPU profile from production using
runtime/pprofornet/http/pprof. - The standard approach to building is to store a pprof CPU profile with filename default.pgo in the main package directory of the profiled binary. (S1)
- Build normally;
-pgo=autois the default.
Notes
- PGO is also called feedback-directed optimization (FDO).
Claims
- id: C1 claim: The Go compiler supports PGO starting in Go 1.20. source: S1 evidence: "Starting in Go 1.20, the Go compiler supports profile-guided optimization (PGO) to further optimize builds."
- id: C2 claim: PGO improves performance by around 2-14% as of Go 1.22. source: S1 evidence: "building with PGO improves performance by around 2-14%"
- id: C3 claim: go build detects default.pgo files automatically. source: S1 evidence: "By default, go build will detect default.pgo files automatically and enable PGO."
- id: C4 claim: The compiler uses CPU pprof profiles as input. source: S1 evidence: "In Go, the compiler uses CPU pprof profiles as the input profile"
- id: C5 claim: PGO in Go 1.21 is ready for production use. source: S2 evidence: "PGO support in Go 1.21 is ready for general production use!"
Sources
- [S1] Profile-guided optimization - The Go Programming Language. The Go Authors (go.dev). https://go.dev/doc/pgo . License: CC BY 4.0 (go.dev text). Accessed 2026-11-04.
- [S2] Profile-guided optimization in Go 1.21 - The Go Programming Language. The Go Authors (go.dev). https://go.dev/blog/pgo . License: CC BY 4.0 (go.dev text). Accessed 2026-11-04.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Go Authors (go.dev), Profile-guided optimization - The Go Programming Language, CC BY 4.0 (go.dev text); The Go Authors (go.dev), Profile-guided optimization in Go 1.21 - The Go Programming Language, CC BY 4.0 (go.dev text).
Cite this
iinventedlight. 2026. "Profile-guided optimization (PGO) in Go." iinventedlight Library, iil:note:q4pqb1nw, version of 2026-11-04. https://iinventedlight.com/library/notes/go-profile-guided-optimization/. License: CC-BY-4.0.
@misc{iil_note_q4pqb1nw,
author = {{iinventedlight}},
title = {{Profile-guided optimization (PGO) in Go}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/go-profile-guided-optimization/},
note = {Permanent ID iil:note:q4pqb1nw. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/go-profile-guided-optimization.md.