Profile-guided optimization (PGO, sometimes pronounced as pogo), also known as profile-directed feedback (PDF), and feedback-directed optimization (FDO) is a compiler optimization technique in computer programming that uses profiling to improve program runtime performance.
Optimization techniques based on static program analysis of the source code consider code performance improvements without actually executing the program. No dynamic program analysis is performed. The analysis may even consider code within loops including the number of times the loop will execute, for example in loop unrolling. In the absence of all the run time information, static program analysis can not take into account how frequently that code section is actually executed.
The first high-level compiler, introduced as the Fortran Automatic Coding System in 1957, broke the code into blocks and devised a table of the frequency each block is executed via a simulated execution of the code in a Monte Carlo fashion in which the outcome of conditional transfers (as via
IF-type statements) is determined by a random number generator suitably weighted by whatever
FREQUENCY statements were provided by the programmer.
Rather than programmer-supplied frequency information, profile-guided optimization uses the results of profiling test runs of the instrumented program to optimize the final generated code.  The compiler accesses profile data from a sample run of the program across a representative input set. The results indicate which areas of the program are executed more frequently, and which areas are executed less frequently. All optimizations benefit from profile-guided feedback because they are less reliant on heuristics when making compilation decisions. The caveat, however, is that the sample of data fed to the program during the profiling stage must be statistically representative of the typical usage scenarios; otherwise, profile-guided feedback has the potential to harm the overall performance of the final build instead of improving it.
Just-in-time compilation can make use of runtime information to dynamically recompile parts of the executed code to generate a more efficient native code. If the dynamic profile changes during execution, it can deoptimize the previous native code, and generate a new code optimized with the information from the new profile.
There is support for building Firefox using PGO. Even though PGO is effective, it has not been widely adopted by software projects, due to its tedious dual-compilation model. It is also possible to perform PGO without instrumentation by collecting a profile using hardware performance counters. This sampling-based approach has a much lower overhead and does not require a special compilation.
The HotSpot Java virtual machine (JVM) uses profile-guided optimization to dynamically generate native code. As a consequence, a software binary is optimized for the actual load it is receiving. If the load changes, adaptive optimization can dynamically recompile the running software to optimize it for the new load. This means that all software executed on the HotSpot JVM effectively make use of profile-guided optimization.
PGO has been adopted in the Microsoft Windows version of Google Chrome. PGO was enabled in the 64-bit edition of Chrome starting with version 53 and version 54 for the 32-bit edition.
Google published a paper  describing a system (AutoFDO) in use for using production profiles to guide builds resulting in up to a 10% performance improvement.
Examples of compilers that implement PGO are:
- Intel C++ Compiler and Fortran compilers
- GNU Compiler Collection compilers
- Oracle Solaris Studio (formerly called Sun Studio)
- Microsoft Visual C++ compiler
- IBM XL C/C++
- GraalVM Enterprise Edition
- .NET JIT compiler
- Adaptive optimization
- Dynamic dead code elimination
- Global optimization
- Hot spot (computer programming)
- Interprocedural optimization
- Link-time optimization (LTO)
- Tracing just-in-time compilation
- ↑ 1.0 1.1 "Microsoft Visual C++ Team Blog". 12 November 2008. https://devblogs.microsoft.com/cppblog/pogo/.
- ↑ "Profile-directed feedback (PDF)". http://pic.dhe.ibm.com/infocenter/comphelp/v111v131/index.jsp?topic=%2Fcom.ibm.xlf131.aix.doc%2Fproguide%2Foptimizepdf.html.
- ↑ Baptiste Wicht, Roberto A. Vitillo, Dehao Chen, David Levinthal (24 November 2014). Hardware Counted Profile-Guided Optimization. Bibcode: 2014arXiv1411.6361W.
- ↑ J. W. Backus, R. J. Beeber, et al., The Fortran Automatic Coding System, Proceedings of the Western Joint Computer Conference, February 1957, p. 195
- ↑ "K. Pettis, R. Hansen, Profile Guided Code Positioning, ACM SIGPLAN Programming Language Design and Implementation Conference 1990". http://pages.cs.wisc.edu/~fischer/cs701.f05/code.positioning.pdf.
- ↑ 6.0 6.1 "Intel Fortran Compiler 10.1, Professional and Standard Editions, for Mac OS X". http://www.softmartonline.com/intel/compilers/reseller_productpage_fortran_compiler_mac.htm#Profile-guided%20Optimization.
- ↑ "Profile-Guided Optimization (PGO) Quick Reference". http://software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/cpp/win/compiler_c/optaps/common/optaps_pgo_bsic.htm.
- ↑ Building with Profile-Guided Optimization, mozilla.org, 13 August 2013
- ↑ 9.0 9.1 Dehao Chen (2010), "Taming hardware event samples for fdo compilation", Proceedings of the 8th annual IEEE/ACM international symposium on Code generation and optimization, pp. 42–52.
- ↑ Ivanov, Vladimir (25 July 2013). "JVM JIT compilation overview". http://www.slideshare.net/ZeroTurnaround/vladimir-ivanovjvmjitcompilationoverview-24613146.
- ↑ Marchand, Sébastien (31 October 2016). "Making Chrome on Windows faster with PGO". https://blog.chromium.org/2016/10/making-chrome-on-windows-faster-with-pgo.html.
- ↑ Chen, Dehao; Li, David Xinliang; Moseley, Tipp (2016). "AutoFDO: Automatic Feedback-Directed Optimization for Warehouse-Scale Applications". CGO 2016 Proceedings of the 2016 International Symposium on Code Generation and Optimization (New York, NY, USA): 12–23. doi:10.1145/2854038.2854044. ISBN 9781450337786. https://research.google/pubs/pub45290/.
- ↑ 1. Install prerequisite, Google, 2022-06-14, https://github.com/google/autofdo, retrieved 2022-06-21
- ↑ "Profile-guided optimizations[VS 2019"]. https://docs.microsoft.com/en-us/cpp/build/profile-guided-optimizations?view=msvc-160.
- ↑ "Profile-guided optimization [Clang Compiler User's Manual"]. https://clang.llvm.org/docs/UsersManual.html#profile-guided-optimization.
- ↑ Quintero, Dino; Chabrolles, Sebastien; Chen, Chi Hui; Dhandapani, Murali; Holloway, Talor; Jadhav, Chandrakant; Kim, Sae Kee; Kurian, Sijo et al. (1 May 2013). IBM Power Systems Performance Guide: Implementing and Optimizing. IBM Redbooks. ISBN 9780738437668. https://books.google.com/books?id=lHTJAgAAQBAJ&q=profiel+directed+feedback&pg=PA300.
- ↑ "Optimize a Native Executable with Profile-Guided Optimizations [GraalVM How-to Guides"]. https://www.graalvm.org/latest/reference-manual/native-image/guides/optimize-native-executable-with-pgo/.
- ↑ "What's new in .NET 6: Profile-guided optimization". https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-6#profile-guided-optimization.
Original source: https://en.wikipedia.org/wiki/Profile-guided optimization. Read more