3 ms·
> because the JIT can perform optimisations which are impossible for the compiler Is there an example of at least one such optimization? As JIT is not magic, i
by zzzcpan 8y ago
> because the JIT can perform optimisations which are impossible for the compiler
Is there an example of at least one such optimization? As JIT is not magic, it also compiles things ahead of time, but a little bit ahead of time and it is very constrained on how much time and resources it can waste. It also can't afford to slow down interpreter too much, can't do excessive profiling, can't do big changes to the code that touch half of all the functions and data structures for example, etc. While AOT can do that and I can't think of anything JIT does that AOT can't do.
- simiones 8y agoOne such example is dynamic re-compilation in Java, with e.g. inlining or uninlining based on recent profiling. This would handle the case where a certain (large-ish) function is on a branch that's often taken for some stable amount of time (where inlining gets rid of method call overhead), then often not taken for other periods of time (where un-inlining gets rid of the instruction cache bloat). Artificial example: while (true) { if (timeOfDay < NOON) { computePi(); //should be inlined before noon, function call after noon } else { computeE(); //inline after noon, function call before } }