-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Background and motivation
We want users to be able to easily enable the Dynamic PGO feature in .NET 7.0. Currently it's not as convenient as it could be: users have to define a set of environment variables and make sure those are defined in the process of app's execution (it's especially complicated for asp.net scenarios) - I have a small write-up here. We define three modes for PGO:
Default- Current DefaultFull- All R2R images are ignored, everything is compiled and profiled from scratch. Noticeable startup regression with the most performant steady state.Dynamicor e.g.HybridorMixed- JIT only instruments functions without R2R data. (NOTE: it doesn't mean such functions won't benefit from PGO - e.g. lots of BCL's code contains a "generic" profile baked into R2R which is then used by the tiered JIT for tier1) - a balance between start up time and performance. Eventually, we hope that this mode will be the default one.
A good visualization of the difference between these modes is this TE benchmark:

Full significantly regresses "time to first request" but provides the best performance. Dynamic still slightly regresses "time to first request" but eventually we plan to reduce overhead from instrumentation in tier0 and minimize it.
Proposal & Usage
Add a runtime switch for .csproj:
<PgoMode>full</PgoMode>
and runtimeconfig.json:
"System.Runtime.PgoMode": dynamic
(in dotnet/sdk project)
Where full basically sets DOTNET_ReadyToRun=false and DOTNET_TieredPGO=true internally and dynamic only defines DOTNET_TieredPGO=true (OSR and QJFL are already enabled by default in .NET 7.0 and omitted here)
Alternative Designs
-
<OptimizeFor>
Alternatively, we can encapsulate all of that into a generic<OptimizeFor>property with "FastStartup", "MaxPerformance", "SmallWorkingSet" values and rely on them in JIT/VM/BCL in various places, not just for PGO -
<DynamicPgo>true</DynamicPgo>and<IgnoreR2R>true</IgnoreR2R>
Define two simple bool properties, where<IgnoreR2R>true</IgnoreR2R>is added only whenFullPgomode is requested.
cc @richlander @terrajobst @AndyAyersMS @davidwrighton @dotnet/jit-contrib