IT lexicon › Programming › Profile-guided optimization (PGO)

Profile-guided optimization (PGO)

Programming På svenska → Updated: 2026-11-05

The program is first run on a real workload, then recompiled with hard data on which paths were actually hot.

Otherwise a compiler guesses: which branch is usually taken, which functions are worth inlining, which code can be moved out of the way. With PGO you build an instrumented binary (-fprofile-generate in GCC and Clang), run it on representative input and rebuild with -fprofile-use. Hot code is then packed tightly together, which helps both the cache and branch prediction.

Gains of 10–20 percent are common for large programs like browsers and databases, and Python's --enable-optimizations is PGO under the hood. The weakness is that the profile lies if the training run doesn't resemble reality. Google's AutoFDO and Meta's BOLT therefore sample in production instead, and Go got built-in PGO in 2023. JIT compilers do essentially the same thing continuously, at run time.

← Back to the lexicon