0

Why do CLR need JIT compiler to complie IL to machine code when it has NGEN that does that work at the time of installation.

One more question, how JIT will complie IL code if it is already NGENed?

Imad
  • 7,126
  • 12
  • 55
  • 112

2 Answers2

3
  • because many apps aren't "installed" in that sense, and don't make use of the structures that NGEN require; they are just files on a storage device (or purely in memory, if loaded from an external source)
  • because NGEN is tied to hardware, and hardware can change during a machine's life
  • because the JIT itself can be updated separately to your applications, fixing bugs and improving performance
  • because apps use things like plugins and extension points; everything might not be available when you NGEN
  • because many apps use meta-programming to emit optimized code for themselves at runtime based on the exact conditions (which could be external data not knowable until it is actually invoked at runtime - how ORMs map database columns to objects, for example)
  • because in many cases it isn't worth the overhead of NGEN - it won't improve things

When NGEN or AOT is a good fit: great, go do that. But it isn't a magic wand that solves every problem.

One more question, how JIT will complie IL code if it is already NGENed?

Assuming that all the preconditions for the NGEN image being a perfect match are satisfied, then the JIT won't need to be involved.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
1

This post has some explanations why NGEN might be not as attractive as it sounds.

And here there are very old recommendations from Microsoft when to use NGEN.

One more question, how JIT will complie IL code if it is already NGENed?

If runtime decides that recompilation is required - it'll ignore NGENed image altogether.

Ricardo Pontual
  • 3,749
  • 3
  • 28
  • 43
Igor Labutin
  • 1,406
  • 10
  • 10