Thursday, November 21, 2013

State of ART: A new Android RunTime

With the release of Android 4.4 KitKat, Google introduced a new Runtime environment. Named as ART, an acronym for Android RunTime, it is deployed to help Android perform better. With the consistent 5 year use of default runtime Dalvik, KitKat ships with both runtimes available to be used.

But hey, what’s Dalvik?

The word “Runtime Environment” is the software environment created by the Operating System when a software is it in its running state. Dalvik is no exception. It is a process Virtual Machine RTE (Run Time Environment) that Google uses to run apps in Android OS. It is the base layer of the Android Apps. On the top of it, the Android apps execute. Android apps are coded in Java, and that code is converted to a code which is handled by Dalvik.

By the way, how does it work?

Dalvik has a Just-In-Time (JIT) Compiler. The Just In Time code means that code which is not compiled already, but when required, it gets converted to the executable code. The best example is Javascript code. A Javascript code always stays as non-precompiled in the website directory, but when user clicks on some spot where it is called, the code gets converted to an executable state.

Similarly Dalvik works. Android apps are not the compiled code, they are in a simply packed form. After installation, it gets stored on the hard disk of the phone (or a tablet). When it is executed, Android combines all the uncompiled code together, complies it and converts the code in Dalvik Executable .dex format. Then this .dex file is executed by Dalvik.
It is always a good option for application environments, but what the problem is that the dalvik executable takes much execution time and also battery hogs and CPU loads. Although it is not that much as it sounds, but still in the world where a single cycle of CPU and response time matters, Dalvik is not matching the requirements.

So, here we’ve got ART 

As an alternative solution to Dalvik, Google came with a new runtime environment called as “ART” or Android RunTime. ART incorporates AOT (Ahead-Of-Time) compiler, rather than JIT compiler. Instead of compiling the code at the time of calling, this environment has a different policy. Once an app is downloaded, it unpacks and gets compiled. If the user opens the app, the app opens up faster than Dalvik. This is because in ART there’s no compilation process occurs, hence it saves the processing time. Although it takes more space on the disk, but it results in lesser CPU usage and battery drain.

Google has kept ART turned off by default. Users can always switch from Dalvik to ART from Settings > Developer Options > Select Runtime.

Is it really faster?

Developers, those who have tested apps on ART, have said apps to be working 50% faster than in Dalvik. The small apps don’t have a notable difference, but large apps such as Photoshop Touch accounted fast opening in ART mode. Currently ART is in the testing phase. Not all of the apps work in the new environment.

The reason that developers should switch to start using ART Dalvik over ART is that they need to write the same code, and it results in faster apps. There is less UI latency, faster response, lesser battery drain and CPU usage gets reduced. ART is the future of Android. Google has worked two years to develop it, and finally it has made its inside the OS. 

Oh yes, by the way, following video shows Dalvik v/s ART which we found on YouTube.


Sample Text

Sample Text