In
computer programming
Computer programming or coding is the composition of sequences of instructions, called computer program, programs, that computers can follow to perform tasks. It involves designing and implementing algorithms, step-by-step specifications of proc ...
, profile-guided optimization (PGO, sometimes pronounced as ''pogo''
), also known as profile-directed feedback (PDF) or feedback-directed optimization (FDO), is the
compiler optimization technique of using prior analyses of software artifacts or behaviors ("
profiling") to improve the expected
runtime performance of the program.
Method
Optimization techniques based on
static program analysis of the
source code
In computing, source code, or simply code or source, is a plain text computer program written in a programming language. A programmer writes the human readable source code to control the behavior of a computer.
Since a computer, at base, only ...
consider code performance improvements without actually executing the program. No
dynamic program analysis
Dynamics (from Greek δυναμικός ''dynamikos'' "powerful", from δύναμις ''dynamis'' " power") or dynamic may refer to:
Physics and engineering
* Dynamics (mechanics), the study of forces and their effect on motion
Brands and en ...
is performed. For example, inferring or placing formal constraints on the number of iterations a
loop is likely to execute is fundamentally useful when considering whether to
unroll it or not, but such facts typically rely on complex runtime factors that are difficult to conclusively establish. Usually, static analysis will have incomplete information and only be able to approximate estimates of the eventual runtime conditions.
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
Monte Carlo ( ; ; or colloquially ; , ; ) is an official administrative area of Monaco, specifically the Ward (country subdivision), ward of Monte Carlo/Spélugues, where the Monte Carlo Casino is located. Informally, the name also refers to ...
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 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
Mozilla Firefox, or simply Firefox, is a free and open-source web browser developed by the Mozilla Foundation and its subsidiary, the Mozilla Corporation. It uses the Gecko rendering engine to display web pages, which implements curr ...
using PGO.
[Building with Profile-Guided Optimization](_blank)
mozilla.org, 13 August 2013 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.
[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. This sampling-based approach has a much lower overhead and does not require a special compilation.
The
HotSpot Java virtual machine
A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally descr ...
(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
Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
version of
Google Chrome
Google Chrome is a web browser developed by Google. It was first released in 2008 for Microsoft Windows, built with free software components from Apple WebKit and Mozilla Firefox. Versions were later released for Linux, macOS, iOS, iPadOS, an ...
. 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
toolin use for using production profiles to guide builds resulting in up to a 10% performance improvement.
Implementations
Examples of compilers that implement PGO are:
*
Intel C++ Compiler and
Fortran compilers
*
GNU Compiler Collection
The GNU Compiler Collection (GCC) is a collection of compilers from the GNU Project that support various programming languages, Computer architecture, hardware architectures, and operating systems. The Free Software Foundation (FSF) distributes ...
compilers
*
Oracle Solaris Studio (formerly called Sun Studio)
*
Microsoft Visual C++ compiler
*
Clang
Clang () is a compiler front end for the programming languages C, C++, Objective-C, Objective-C++, and the software frameworks OpenMP, OpenCL, RenderScript, CUDA, SYCL, and HIP. It acts as a drop-in replacement for the GNU Compiler ...
*
IBM XL C/C++
*
GraalVM Enterprise Edition
*
.NET
The .NET platform (pronounced as "''dot net"'') is a free and open-source, managed code, managed computer software framework for Microsoft Windows, Windows, Linux, and macOS operating systems. The project is mainly developed by Microsoft emplo ...
JIT compiler
*
Go
See also
*
Adaptive optimization
*
Dynamic dead code elimination
*
Global optimization
*
Hot spot (computer programming)
*
Interprocedural optimization
**
Link-time optimization (LTO)
*
Tracing just-in-time compilation
References
{{Compiler optimizations
Compiler optimizations