---
source: https://iinventedlight.com/library/notes/go-profile-guided-optimization.md
title: "Profile-guided optimization (PGO) in Go"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC BY 4.0 (go.dev text); prose restates cited source lines"
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: Go"
tags: ['go', 'performance', 'pgo', 'compiler']
sources:
  - id: S1
    title: "Profile-guided optimization - The Go Programming Language"
    publisher: The Go Authors (go.dev)
    url: https://go.dev/doc/pgo
    accessed: 2026-11-04
    license: "CC BY 4.0 (go.dev text)"
  - id: S2
    title: "Profile-guided optimization in Go 1.21 - The Go Programming Language"
    publisher: The Go Authors (go.dev)
    url: https://go.dev/blog/pgo
    accessed: 2026-11-04
    license: "CC BY 4.0 (go.dev text)"
---
# 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

1. Collect a CPU profile from production using `runtime/pprof` or `net/http/pprof`.
2. 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)
3. Build normally; `-pgo=auto` is 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).
