A new runtime in Android may soon replace Dalvik.
Android apps run in Dalvik. We know this as sure as the sun rises in the morning and water is wet. It is the foundation of how Android apps can run on a variety of devices with different amounts of RAM and processors.
In the near future, Google may be getting rid of Dalvik for a new standard that runs Android apps called Android Runtime (ART).
Dalvik is the virtual machine that compiles the code that make your Android apps work. Typically, Android apps are written in the Java programming language and compiled into bytecode—the generic numeric code that is submitted by developers to app stores like Google Play (the same code makes it less processor intensive to run on a variety of devices). That bytecode is then transferred from a Java Virtual Machine file to a Dalvik executable file.
You may think that all your apps and the code that makes them live in a happy place somewhere inside your smartphone. Really, they don’t. That happy place doesn’t exist. In reality, every time you run an app, the bytecode that comprises the program is run through a compiler that makes it work. In Android, this is done through a process known as a “Just In Time” (JIT) compiler that translates the universal bytecode into machine code, which in turn becomes a hardware-specific program known as an app. This is essentially what Dalvik in Android does.
Imagine: every time you open an app, all the different parts of the smartphone responsible for making that app work have to scramble to assemble the code for the app to make it work on your device. You close the app and all those parts relax. You open it and they scramble again. This is not a very efficient way to run apps but it allows those apps to run basically anywhere (it was one of the reasons it was so easy for BlackBerry to port Android apps to the BlackBerry 10).
With Android Runtime, Google will attempt to change this process so that apps run faster and are more tied to the hardware of the device than ever.
What Is ART?
I first ran into Android Runtime—ART—earlier this week when diddling with the developer settings on the Nexus 5. It is presented in the Developer Options settings of the device as “Select Runtime.” “Use Dalvik” or “Use ART” are the options.
There has not been a lot written about ART but Android Police seems to have the scoop. ART has been secretly in the works from Google for about two years. ART uses an “Ahead Of Time” (AOT) compiler instead of JIT. It is like a Web browser pre-caching websites to be able to load them faster. The AOT compiler translates the bytecode into machine code when an app is downloaded on a device. This machine code may take up more storage memory on a device, but it will make apps open faster and run smoother than before.
Hidden within Google’s Android developer website is a very short introduction to ART:
ART is a new Android runtime being introduced experimentally in the 4.4 release. This is a preview of work in progress in KitKat that can be turned on in Settings > developer options. This is available for the purpose of obtaining early developer and partner feedback.
Important: Dalvik must remain the default runtime or you risk breaking your Android implementations and third-party applications.
Two runtimes are now available, the existing Dalvik runtime (libdvm.so) and the ART (libart.so). A device can be built using either or both. (You can dual boot from Developer options if both are installed.)
The important note here is that ART is an experimental setting for developers and device manufacturers. It can lead to instability of the operating system, cause apps to crash constantly and basically turn your Nexus 5 into a worthless hunk of attractively lasered plastic.
Cody Toombs of Android Police outlines the potential benefits of ART:
Thus far, estimates and some benchmarks suggest that the new runtime is already capable of cutting execution time in half for most applications. This means that long-running, processor-intensive tasks will be able to finish faster, allowing the system to idle more often and for longer. Regular applications will also benefit from smoother animations and more instantaneous responses to touch and other sensor data. Additionally, now that the typical device contains a quad-core (or greater) processor, many situations will call for activating fewer cores, and it may be possible to make even better use of the lower-powered cores in ARM’s big.LITTLE architecture. How much this improves battery life and performance will vary quite a bit based on usage scenarios and hardware, but the results could be substantial.
Are we soon to see the end of Dalvik in favor of a more efficient runtime that could make Android apps perform much, much better? Probably not quite yet. Google will test ART with its manufacturing partners and developers for the foreseeable future. If ART works like it is supposed to, all that scrambling within a smartphone to make an app work will stop and the code that runs the app will just be there on your device, waiting for you to open it.