Skip to main content
A newer version of this page is available. .

Reducing the Application Launch Time

  • 3 minutes to read

When you build a .NET application, it is compiled into Microsoft Intermediate Language (MSIL). When a user launches the application, its MSIL code is compiled into machine code by the “just in time” (JIT) compiler. This process can cause noticeable delays. External DLLs (e.g. the DevExpress ones) may be loaded in addition to your own application, which means that any delay does not depend on the size of your code alone.

This topic describes how to reduce the WPF application startup time if you have noticeable delays in your application due to the JIT compilation.

Compile IL code into native code

Use the Native Image Generator (Ngen.exe) tool to compile assemblies’ IL code into native code. When an end-user runs your application, CLR loads the precompiled code from the native image cache, so that no compilation is required at runtime. The Ngen.exe tool ships with the .NET Framework SDK.

You can compile your application’s (and its dependencies) IL code into native code like follows:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe install C:\MyApp.exe 

Run Ngen.exe after your application’s deployment.

Note

NGen.exe produces code that is not as highly optimized as the JIT compiler–produced code.

Refer to the Ngen.exe (Native Image Generator) article for information about various native image generation capabilities.

Use MultiCore JIT

Starting with the .NET Framework 4.5, you can use the System.Runtime.ProfileOptimization class to enable Multicore JIT. Multicore JIT uses parallelization to reduce the JIT compilation time during application startup.

Note

Using the MultiCore JIT is not as effective as compiling IL code into native code.

The code sample below demonstrates how to enable Multicore JIT in your application.

public App() 
{
    // Defines where to store JIT profiles
    ProfileOptimization.SetProfileRoot(@"C:\MyAppFolder");
    // Enables Multicore JIT with the specified profile
    ProfileOptimization.StartProfile("Startup.Profile");
} 

The first time the application starts, the JIT compiler records every method it should compile. The CLR then saves a profile of the methods that were executed. The ProfileOptimization.SetProfileRoot method specifies an existing folder where the profiles are saved. Multicore JIT is not applied at this moment.

The second time the application runs, the ProfileOptimization.StartProfile method loads the specified profile from disk and uses this information to compile methods in the background before they are called from the main thread.

Refer to the following articles for more information: