Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How a JIT compiler helps performance of applications?

I just read that Android has a 450% performance improvement because it added a JIT compiler, I know what JIT is, but I don't really understand why is it faster than normal compiled code? or what's the difference with the older approach from the Android platform (the Java like run compiled bytecode).

Thanks!

EDIT: This is hugely interesting, thanks!, I wish I could pick every answer as correct :)

like image 247
igorgue Avatar asked May 13 '10 16:05

igorgue


People also ask

Why JIT compiler is faster?

A JIT compiler can be faster because the machine code is being generated on the exact machine that it will also execute on. This means that the JIT has the best possible information available to it to emit optimized code.

What is the JIT compiler and how does it work?

A Just-In-Time (JIT) compiler is a feature of the run-time interpreter, that instead of interpreting bytecode every time a method is invoked, will compile the bytecode into the machine code instructions of the running machine, and then invoke this object code instead.

What is the significance of just in compiler?

It is the reason to implement the JIT compiler. The JIT compiler accelerates the performance of the application by compiling the bytecode into native machine code. It is enabled by default when a method is invoked.


4 Answers

First a disclaimer, I'm not at all familiar with Android. Anyway...

There are two applications of JIT compilation that I am familiar with. One is to convert from byte-codes into the actual machine instructions. The second is Superoptimisation.

JIT bytecode compilation speeds things up because the bytecodes are only interpeted once, instead of each time it is executed. This is probably the sort of optimisation you are seeing.

JIT superoptimsation, which searches for the truly optimal set of instructions to implement a programs logic, is a little more esoteric. It's probably not what your talking about, though I have read reports of 100% - 200% speed increases as a result.

like image 167
torak Avatar answered Nov 14 '22 23:11

torak


The VM needs to turn compiled byte code into machine instructions to run. Previously this was done using an interpreter which is fine for code that is only invoked once but is suboptimal for functions that are called repeatedly.

The Java VM saw similar speedups when asa JIT-versions of the VM replaced the initial interpreter versions.

like image 43
Christopher Barber Avatar answered Nov 14 '22 21:11

Christopher Barber


The JIT compiler knows about it's system, it can use that knownledge to produce highly efficient code compared to bytecode, and rumors go it can surpass pre-compiled programs.

That's why it can go faster than the traditional system of java, where the code was run as bytecode only, which Android used, too.

like image 36
LukeN Avatar answered Nov 14 '22 22:11

LukeN


Besides compiling java code to native code, which could be done with a compiler too, a JIT does optimizations, that you can only do at runtime.

A JIT can monitor the applications behavior over time and optimize those usage patterns that really make a difference, even at the expense of other branches in the execution path of the code, if those are less frequently used.

like image 23
Mariano Kamp Avatar answered Nov 14 '22 21:11

Mariano Kamp