.NET CLR Jitting Documentation

Just-In-Time (JIT) Compilation

The JIT compiler transforms Microsoft Intermediate Language (MSIL) into native machine code at runtime. This process optimizes execution based on the current environment, enabling .NET applications to run efficiently on diverse hardware.

How JIT Works

  1. Method call triggers JIT.
  2. MSIL is retrieved from the assembly.
  3. JIT compiles MSIL to native code.
  4. Native code is cached for subsequent calls.
public int Add(int a, int b) => a + b;
// First call triggers JIT
int result = Add(2,3);

JIT Compilation Modes

ModeDescription
RyuJITDefault x86/x64 JIT in .NET Core/5+
LegacyJITOlder JIT used by .NET Framework
Tiered CompilationInitial quick compile, later optimized tier

Configuring JIT

Adjust JIT behavior via runtime configuration or environment variables.

{
  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true,
      "System.Runtime.TieredCompilation": false
    }
  }
}

Performance Tips