Description
From Profile Guided Optimization
Profile information enables better optimization. For example, knowing that a branch is taken very frequently helps the compiler make better decisions when ordering basic blocks. Knowing that a function foo is called more frequently than another function bar helps the inliner. Optimization levels -O2 and above are recommended for use of profile guided optimization.
Clang supports profile guided optimization with two different kinds of profiling. A sampling profiler can generate a profile with very low runtime overhead, or you can build an instrumented version of the code that collects more detailed profile information. Both kinds of profiles can provide execution counts for instructions in the code and information on branches taken and function invocation.
Regardless of which kind of profiling you use, be careful to collect profiles by running your code with inputs that are representative of the typical behavior. Code that is not exercised in the profile will be optimized as if it is unimportant, and the compiler may make poor optimization choices for code that is disproportionately used while profiling.
Chromium build configuration has opt-in support for PGO https://chromium.googlesource.com/chromium/src.git/+/refs/heads/main/docs/pgo.md. The issue is to track the effort of optimizing the Electron runtime with PGO for VSCode. This will be a multi-step process and initially some manual steps are also involved, we will investigate automating the whole flow if the results are satisfying.
For this experiment, we are using the instrumented version to collect the profile. Steps involved are as follows,
Instrumentation Phase
Building
- 🏃 Create MS Electron builds with following additional build flags
chrome_pgo_phase = 1
enable_resource_allowlist_generation = false
- Create nightly exploration builds based on the above custom runtime build
Running
- Get builds from https://builds.code.visualstudio.com/builds/exploration corresponding to the branch robo/explore_pgo
NB: Builds from branch robo/explore_pgo will always reflect latest changes from
main
, only difference is the instrumented runtime build, so it will not affect your everyday use.
-
Selfhost on the build and perform your everyday tasks, at the end of every run files with extension
*.profraw
will be generated in the user data directory underPGO_Profiles
folder. -
🏃 At EOD, upload the generated
*.profraw
files to#proj-pgo
channel
NB: There is no limit on the number of days to selfhost on this build during the experiment. Scheduled nightly updates will be available.
Optimization Phase
Building
- Combine the
.profraw
files into.profdata
using llvm-profdata script - Build MS Electron builds with generated
.profdata
using the following build flags
chrome_pgo_phase = 2
pgo_data_path = {path-to-the-profdata}
- Test startup numbers and feed this build into the instrumentation phase until a stable range is obtained.
- Ship optimized build to Insiders
- Ship optimized build to Stable