.NET Native and JIT compilation
JIT compilation is done mostly at runtime, and it converts the MSIL code to the native machine code. This is when the code is run the first time, and it takes a little bit more time than its successive runs. In .NET Core today, we are developing applications for mobile and handheld devices that have limited resources in terms of CPU power and memory. Currently, the Universal Windows Platform (UWP) and the Xamarin platform run on .NET Core. With these platforms, .NET Core automatically generates that native assembly at compilation time or while generating the platform-specific packages. Though it does not require the JIT compilation process to be done at runtime, this eventually increases the performance of the application's boot-up time. This native compilation is done through a component known as .NET Native.
.NET Native begins the compilation process after the language-specific compiler finishes up the compilation process that is done at build time. The .NET Native toolchain reads the MSIL generated from the language compiler and performs the following operations:
- It eliminates the metadata from the MSIL.
- It replaces the code that relies on reflection and metadata with the static native code when comparing field values.
- It checks the code that is invoked by the application and includes only that in the final assembly.
- It replaces the full CLR with a refactored runtime that contains the garbage collector and no JIT compiler. The refactored runtime goes with the app and is contained in the assembly named mrt100_app.dll.