Google
is moving from Dalvik
to ART
(Android Runtime).
I was trying to understand, how it is going to improve the performance.
The best explanation I found is the below image:
One of the main component which has changed is dexopt
to dex2oat
.
Since I don't have much idea about these, can anyone explain the difference and how this is going to improve the performance?
dexopt does some optimizations on the dex file. It does things like replacing a virtual invoke instruction with an optimized version that includes the vtable index of the method being called, so that it doesn't have to perform a method lookup during execution.
The result of dexopt is an odex (optimized dex) file. This is very similar to the original dex file, except that it uses some optimized opcodes, like the optimized invoke virtual instruction.
dex2oat takes a dex file and compiles it. The result is essentially an elf file that is then executed natively. So instead of having bytecode that is interpreted by a virtual machine, it now has native code that can be executed natively by the processor. This is called AOT (ahead-of-time) compilation.
Both tools are normally run at install time on the device.
Another factor to take into account is that dalvik used a JIT (just-in-time) compiler - meaning that it was also able to compile bytecode to native code. The main difference however, is that ART compiles everything ahead of time, whereas dalvik only compiled a subset of the bytecode using heuristics to detect the code that was executed most frequently, and it compiled during execution.