9

In which respects "Just In Time" compilation is better than "Ahead Of Time" compilation? And vice versa.

Gulshan
  • 9,402
  • 10
  • 58
  • 89

1 Answers1

11

Just-in-time compilation usually uses profiling information (like "how many times has this method been executed up to now") to determine how aggressively a given method should be compiled, and is usually included in the execution platform. JIT was brought into focus with the early versions of Java as they could only do simple interpretation, but with hooks allowing for external JIT modules to be plugged in allowing for vast improvements of execution speed.

Ahead-of-time compilation is - to my knowledge - a term coined to complement the JIT concept, and usually reflects a compilation step done before execution which rarely includes profiling information (so all methods are compiled equally hard). The optimization step is finished at runtime, so it does not need to be present at execution time. This mean that the execution environment does not need to be as big as in the JIT-environment.

One of the big advantages of JIT-compilation, is that it allows directly targetting the exact hardware at each run utilizing things like SSE3 or AltiVec, instead of having to compile to a common subset available on all platforms.

Note, however, that the JIT-process is usually hard to predict what it will do. You generally cannot figure out how to "trick" it to do something special with gnarly code, as it may change in the next release. This means that it is very important to write clean, simple code giving the JIT the best possible conditions to do its work.