Why does .net use a JIT compiler instead of just compiling the code once on the target machine?

Viewed 5644

The title pretty much sums it up but I was wondering why systems like .net compile code every time it is run instead of just compiling it once on the target machine?

6 Answers

The title pretty much sums it up but I was wondering why systems like .net compile code every time it is run instead of just compiling it once on the target machine?

.NET does cache the results of compiling CIL to native code on a given target but this is not trivial:

  • There is a trade-off between loading cached data from disk and recompiling on-the-fly.
  • Any form of run-time code generation requires the ability to compile on-the-fly. This is not only the use of System.Reflection.Emit but also reification of types from dynamically-loaded assemblies and even the creation of new value types during polymorphic recursion.
Related