Profile-guided optimization

From HandWiki
Revision as of 21:57, 6 February 2024 by Rjetedi (talk | contribs) (over-write)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Short description: Compiler optimization technique

Profile-guided optimization (PGO, sometimes pronounced as pogo[1]), also known as profile-directed feedback (PDF),[2] and feedback-directed optimization (FDO)[3] is a compiler optimization technique in computer programming that uses profiling to improve program runtime performance.

Method

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.[4]

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.[5] [6][7] 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.

Adoption

There is support for building Firefox using PGO.[8] Even though PGO is effective, it has not been widely adopted by software projects, due to its tedious dual-compilation model.[9] It is also possible to perform PGO without instrumentation by collecting a profile using hardware performance counters.[9] 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.[10]

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.[11]

Google published a paper [12] describing a tool in use for using production profiles to guide builds resulting in up to a 10% performance improvement.

Implementations

Examples of compilers that implement PGO are:

See also

References

  1. 1.0 1.1 "Microsoft Visual C++ Team Blog". 12 November 2008. https://devblogs.microsoft.com/cppblog/pogo/. 
  2. "Profile-directed feedback (PDF)". http://pic.dhe.ibm.com/infocenter/comphelp/v111v131/index.jsp?topic=%2Fcom.ibm.xlf131.aix.doc%2Fproguide%2Foptimizepdf.html. 
  3. Baptiste Wicht; Roberto A. Vitillo; Dehao Chen; David Levinthal (24 November 2014). Hardware Counted Profile-Guided Optimization. Bibcode2014arXiv1411.6361W. 
  4. J. W. Backus, R. J. Beeber, et al., The Fortran Automatic Coding System, Proceedings of the Western Joint Computer Conference, February 1957, p. 195
  5. "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. 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. 
  7. "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. 
  8. Building with Profile-Guided Optimization, mozilla.org, 13 August 2013
  9. 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.
  10. Ivanov, Vladimir (25 July 2013). "JVM JIT compilation overview". http://www.slideshare.net/ZeroTurnaround/vladimir-ivanovjvmjitcompilationoverview-24613146. 
  11. 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. 
  12. Chen, Dehao; Li, David Xinliang; Moseley, Tipp (2016). "AutoFDO: Automatic feedback-directed optimization for warehouse-scale applications". Proceedings of the 2016 International Symposium on Code Generation and Optimization. New York, NY, USA. pp. 12–23. doi:10.1145/2854038.2854044. ISBN 978-1-4503-3778-6. https://research.google/pubs/pub45290/. 
  13. "Profile-guided optimizations[VS 2019"]. 18 October 2022. https://docs.microsoft.com/en-us/cpp/build/profile-guided-optimizations?view=msvc-160. 
  14. "Profile-guided optimization [Clang Compiler User's Manual"]. https://clang.llvm.org/docs/UsersManual.html#profile-guided-optimization. 
  15. 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 978-0-7384-3766-8. https://books.google.com/books?id=lHTJAgAAQBAJ&q=profiel+directed+feedback&pg=PA300. 
  16. "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/. 
  17. "What's new in .NET 6: Profile-guided optimization". 26 May 2023. https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-6#profile-guided-optimization. 
  18. "Profile-guided optimization". https://go.dev/doc/pgo.