[Info] Improve startup time with the Multicore JIT

Mar 6, 2014 at 8:20 PM
Edited May 14, 2016 at 7:37 PM

This article has been moved to GitHub!

Microsoft introduced a Multicore JIT, which uses parallelization to reduce the JIT compilation time during application startup. With Multicore JIT, methods are compiled on two cores in parallel. The more code you execute on your startup path, the more effective Multicore JIT will be at reducing startup time.

In .NET 4.5.1 they improved the Multicore JIT. Now it supports dynamically loaded assemblies as well.

How does it work?
It records the work of the JIT every startup and saves it in a binary “profile” file. The file is quite small. It has about 30KB.

The Multicore JIT reads this file during startup and starts pre-compiling the methods in the background that were recorded in the file.

How to use it?
The Multicore JIT is enabled by default for ASP.NET apps and Silverlight 5 apps. In a desktop application it needs to be enabled via the ProfileOptimization class. This is necessary so that we can tell the CLR where to save the profile file.
var profileRoot = Path.Combine(Environment.GetFolderPath(
        ApplicationInfo.ProductName, "ProfileOptimization");
// Define the folder where to save the profile files
// Start profiling and save it in Startup.profile
Multicore JIT vs. NGET
It is common to use NGEN within the installation for .NET desktop applications. As a result the JIT has not much to do anymore because the assemblies are already pre-compiled. Using the Multicore JIT might still be useful because during development it can reduce the startup time as well.

Further readings
  1. MSDN Blog: An easy solution for improving app launch performance
  2. MSDN Blog: Announcing the .NET Framework 4.5.1 Preview (see chapter: Multi-core JIT improvements)
  3. Ngen.exe (Native Image Generator)