Profile guided optimization
Profile-guided optimization (PGO) is a compilation technology used by C++ compiler to generate optimized code. It applies to the internal native compiled components of the runtime and JIT. It performs compilation in two steps, which are as follows:
- It records the information about code execution.
- From this information, it generates better code.
The following diagram depicts the life cycle of how the code is compiled:
In .NET Core 1.1, Microsoft already released the PGO for Windows X64 architecture, but in .NET Core 2.0, this has been added for both Windows X64 and X86 architectures. Also, as per observatory results, it was noted that the actual startup time is mostly taken by coreclr.dll and clrjit.dll for Windows. Alternatively, on Linux, there are libcoreclr.so and libclrjit.so, respectively.
Comparing RyuJIT with the old JIT compiler known as JIT32, RyuJIT is more efficient in code generation. The startup time of the JIT32 was faster than the RyuJIT; however, the code is not efficient. To overcome the initial startup time taken by the RyuJIT compiler, Microsoft used PGO, which brought the performance closer to JIT32 performance and achieved both efficient code and performance on startup.
For Linux, the compiler toolchain is different for each distro, and Microsoft is working on a separate Linux version of .NET that uses the PGO optimizations applicable to all distros.