Difference between DVM( Dalvik Virtual Machine) and ART

What Is A Runtime Environment?

 Runtime comprises of software instructions that execute when your program is running, even if they’re not essentially are a part of the code of that piece of software in particular. These instructions basically translate the software’s own code into the code that the computer is capable of running. Therefore, all computer languages require some sort of runtime environment that can properly execute the code written in that language.
Android makes use of a virtual machine as its runtime environment in order to run the APK files that constitute an Android application. The advantage of using a virtual machine is twofold – firstly, the app code is isolated from the core operating system, ensuring that should something go wrong, it’s contained in an isolated environment and does not effect the primary OS. And secondly, it allows for cross-compatibility, meaning even if an app is compiled on another platform (such as a PC, as is usually the case with developing mobile apps) , they can still be executed on the mobile platform using the virtual machine.

Why Use A Virtual Machine At All?

That’s actually the point that we touched just above. Virtual machines are slow, there’s no denying that, but they actually hold a couple of advantages that make them a favored choice.
  • Virtual machines supply an isolated environment for code execution. Hence, even if an app contains a malicious piece of code that can damage the core OS, it won’t directly affect the system files, and thus the core OS will be kept from getting corrupted. The large scale benefit is more stability and reliability for the operating system.
  • The app APKs that are supplied through Play Store (or any other source, for that matter) are uncompiled instructions that developers rely on the virtual machine to compile before execution and run on the device. This provides more compatibility; if the developer were to provide already compiled code and it was compiled for a Snapdragon-based processor, it might not run correctly on a Tegra chip, for instance. Hence, this on-the-device compilation addresses this issue.

So, What’s Dalvik, And What’s Wrong With It?

 Dalvik has been there since Android started back in 2007, and it hasn’t changed much since then, apart from the Just-In-Time (JIT) compilation approach approach introduced in Android 2.2 Froyo, which basically compiles apps right when they’re launched, or when the user supplies the necessary instructions. It’s useful, as well as an improvement over the previous conventional interpreter approach that compiled and ran code line by line as it ran, but the downside is a huge overhead when the app is being launched for the first time.
This is because the system needs to pull together all the necessary files, compile the app and load it to RAM. As long as the compiled app stays within the RAM, it will continue to respond snappily, but when you load more apps and the RAM runs out, the first one gets unloaded and hence, upon subsequent launch, the whole process starts over. The approach makes sense on paper, and in fact, has been working fine until now for the platform. However, older devices with limited RAM suffer the most, because the loading/unloading cycle continues more often, and hence, the system feels slow in terms of overall responsiveness. That’s where the new virtual machine, ART, comes in.

What Is ART & How Does It Improve Things?

ART, or Android RunTime (pretty lame name, yeah, we know) is a new experimental virtual machine that Google has introduced with Android 4.4 KitKat as a developer option (with Dalvik still being the one set as default for now). The primary difference between ART and Dalvik is the compilation approach that both of these use – ART employs a new Ahead-Of-Time (AOT) concept contrary to Dalvik’s JIT, which basically compiles apps before they are even launched. What this means is that first-time installs will take longer, and apps will occupy more space on internal storage, but at the same time, since the app will be fully compiled as soon as it’s installed, launch times will be much faster. Likewise, since the compilation part is taken care of just once at the time of install, processor taxing is lower, which results in better battery life and overall performance.

Dalvik Vs. ART – Comparison

Let’s just do a quick comparison of both the virtual machines before moving ahead.
Uses Just-In-Time (JIT) approach, which results in lower storage space consumption but longer app load timesUses Ahead-Of-Time (AOT) approach, which compiles apps when they’re installed, resulting in faster load times and lower processor usage
Cache builds up over time, so boot times are fasterCache is built at first boot, hence rebooting device takes significantly longer
Works better for lower internal storage devices as space occupied is lesserConsumes much more internal storage space since it stores compiled apps in addition to the APKs
Is stable and time tested – VM of choice for app developersIs highly experimental and new – not a lot of support from app developers yet


Post a Comment

Please post comments here:-)

Popular posts from this blog

Android Objective type Question and Answers

Android Questions and Answers for written exams