Advertisement
Intermediate .NET, CLR & Runtime

What is JIT (Just-In-Time) compilation, and how does it differ from ahead-of-time (AOT) compilation?

Short answer

JIT compilation translates IL into native machine code at runtime, immediately before a method is first executed, allowing the CLR to optimize compiled code based on the actual runtime environment (CPU architecture, observed usage patterns) -- at the cost of a warm-up delay for…

Save .NET mock interview
Advertisement
AModel answer
JIT compilation translates IL into native machine code at runtime, immediately before a method is first executed, allowing the CLR to optimize compiled code based on the actual runtime environment (CPU architecture, observed usage patterns) -- at the cost of a warm-up delay for the first call to each method. AOT compilation (like Native AOT) instead compiles everything to native code during the publish/build step, eliminating JIT overhead and warm-up time entirely, at the cost of losing some runtime-adaptive optimization opportunities and dynamic code generation capabilities.
// JIT: method compiled to native code the first time it's called
public void ProcessOrder() { ... }  // IL until first invocation, then JIT-compiled

// Native AOT: entire app compiled to native code at publish time
dotnet publish -p:PublishAot=true
Real-world example
A CLI tool invoked thousands of times per day (like a git hook) benefits significantly from Native AOT's elimination of JIT warm-up, since JIT's per-invocation startup cost would otherwise dominate the tool's very short total runtime.
Likely follow-ups
  • What is tiered compilation and how does it balance JIT startup cost against optimization?
  • Why can't Native AOT support all the same runtime reflection scenarios as JIT?
Related topics