Tech Entice

Dalvik vs ART – Explained : Android to drop Dalvik for more efficient ART

When Google acquired Android Inc. nobody envisioned that in a matter of time, Android would gain such new heights. Android on the upper surface comprises of mostly Java wherein the inside is C/C++(kernel level). So if you try to build applications in Java, you would require the JVM(Java Virtual Machine) to understand your code. But Java (Sun Microsystems) was acquired by Oracle. This was possibly the reason not to use the JVM or any other VM(JRockit) for Android purposes. So what does Google do?

Dalvik is an open source VM created by Dan Bornstein. VM’s can be of two types, Register based or Stack based. While the JVM (Java Virtual Machine) is stack based Dalvik is Register based. Android application runtime must support a diverse set of devices and that applications must be sandboxed for security, performance, and reliability, a virtual machine seems like an obvious choice. Register based VM’s will avoid unnecessary memory access and consume instructions efficiently. Every Android application will be running its own process, with its own instance of the Dalvik VM. Dalvik is made in a way so that a device can run multiple VMs efficiently. The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimized for very low memory. It relies on the underlying Linux kernel for low level memory management. If you are aware of Java then this should be comprehensible. The Java source code of the applications are converted to class files. But the change is that Dalvik will use the “dx” tool to convert class files into “dex” files. Major difference would be a class file will have one class while dex file would have multiple classes. Dalvik is a Just in Time compiler. Compilation is done when the program is running. This is in stark contrast to ART which uses Ahead of time compilation (AOT). JVM along with the .NET framework uses JIT as well.

ART is the new Android runtime being used in Android L. It has come to light that Dalvik will be phased out being replaced by ART. Although it was present in Android Kit Kat as an experiment from before, ART had lot of incompatibilities with lots of applications. This move is beneficial for Google as Oracle has already many lawsuits against them related to Java patents. ART supposedly will improve application performance. It compiles apps using the “dex2oat” tool. This will compile as “dex” files generated by Dalvik VM.

If you know Java, you will also know how much important Garbage Collection is. If Garbage Collector is not efficient in freeing space so allocated to the VM, memory will get consumed faster than memory being released. This results is extremely bad performance. ART promises improved Garbage Collection and Debugging. The AOT produces machine code just like JIT but the difference is that it will transform existing bytecode (generated by VM) into machine code. AOT is used to perform complex and advanced code optimizations. ART should be in theory be better performing than Dalvik.

Well if you are a custom ROM user, do not use Xposed or Gravity Box under ART as they are Dalvik VM optimized. In ART ,applications will launch faster as nothing will be compiled during execution unlike Dalvik. The time taken to boot will also be faster due to the same reason. In theory, this will increase battery backup as well.

Issues that ART brings along are that as it precompiles applications beforehand, it will consume 20% more space than Dalvik. We are yet to have a full feldged ART enabled Android right now but a few experiments done on HTC One M8 with ART enabled instead of Dalvik shows interesting results. Most of the applications did not face any problem to run. Though theoretically ART should improve application performance, but we did not notice any significant difference. But surprisingly in Antutu Benchmark test Dalvik scored higher than ART. In both of the cases high performance mode was activated in developer option.

Dalvik vs Art on HTC One M8

ART is not fully functional yet, but shows great potential. If you want to try ART , you need to enable Developer options first by tapping the Build 7 times. This can be found under Settings–>About

Then go to Developer Option -> select runtime -> Use ART. After you select from Dalvik to ART, your device will reboot and it will take 15-20 minute (depends on number of installed apps) for that first boot to complete. Give it a try, and feel free to share your findings!!

Dalvik vs ART – Explained : Android to drop Dalvik for more efficient ART - Last modify: July 7th, 2014, Author: Abhishek
Report an issue


Human Knowledge belongs to everyone !