Open In App

Difference Between Dalvik and ART in Android

Last Updated : 03 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Android runtime (ART) is the managed runtime used by applications and some system services on Android. ART and its predecessor Dalvik were originally created specifically for the Android project. ART and Dalvik are compatible runtimes running Dex bytecode, so apps developed for Dalvik should work when running with ART. 

Dalvik

Dalvik Virtual Machine or DVM is a Register-Based virtual machine that was designed and written by Dan Bornstein. The Dalvik virtual machine was named by Bornstein after the fishing village “Dalvík” in Eyjafjörður, Iceland, where some of his ancestors used to live. Dalvik is a discontinued process virtual machine (VM) in the Android OS that executes applications written for Android. Dalvik bytecode format is still used as a distribution format, but no longer at runtime in newer Android versions. Android itself is a Linux system with Dalvik sitting on top of it. DVM takes android app, turns them from java code into bytecode that the Linux system can run. Basically, a plain java code is compiled in the JIT compiler to bytecode during runtime to run on the machine. This could lead to a slowdown because compilation at runtime especially during runtime is time-consuming. Hence, manufacturers and OEMs sometimes put out their applications as odexed. There are 2 types of files:

  • .dex(Dalvik Executable file) file is an android’s compiled code file. These .dex files are then zipped into a single .apk file.
  • .odex file is created by the Android operating system to save space and increase the boot speed of an Android app (a .apk file).

dexopt is used to optimize DEX to ODEX (optimized DEX)which contains the optimized bytecode. So the whole process in DVM can be summarized as:

JAVA source code(.java) –> Bytecode(.dex) –> DVM

DVM is better for low storage devices. But it is slower as compilation is done after installation.

Dalvik

ART

With a newer android version specifically from 4.4 version KitKat, there is the concept of ART as an alternative to DVM. ART(Android Run Time) is a successor of DVM which uses the same bytecode and .dex files (but not .odex files), with the succession aiming at performance improvements transparent to the end-users.  Android 5.0 “Lollipop” is the first version in which ART is the only included runtime. Now the thing that ART does is bring apps that are fully compiled when they’re installed on the device. Therefore, higher performance as no need to convert code to bytecode then compile. But the downside is you need more storage space and a little longer to install because of compilation during installation meaning it has to live on the device all the time. Hence, instead of relatively small java code, we have larger bytecode/machine code. You may have heard the terms odexed and de-odexed. What is done in this instance is you take a small part of the application and then precompile it they can go ahead and make a portion of their application optimized to run on their device, and so they’ve now precompiled that section of the app and the rest of its compiled at runtime. So this makes it just a little faster and more performant than in Dalvik. But this approach takes a little more storage space.

Ex: Samsung with TouchWiz .. A lot of stuff, TouchWiz is based on is, precompiled and hence when these are de-odexed, you can retheme/reskin them while losing some performance benefits.

Before reading ahead, remember that the dex2oat is used to optimize and compile .dex into a .oat file which may contain machine code in the ELF format. ART compiles apps using the on-device dex2oat tool. This utility accepts DEX files as input and generates a compiled app executable for the target device. When an app is installed, Android automatically optimizes app data and creates a corresponding OAT file. An OAT file is created by the Android operating system in order to speed up the loading time of an Android app (.APK file).  Android uses this file to load the app more quickly, creating a better user experience.

ART

Difference Between DVM and ART

DALVIK VIRTUAL MACHINE

ANDROID RUN TIME

Faster Booting time Rebooting is significantly longer
Cache builds up overtime The cache is built during the first boot
Occupies less space due to JIT Consumes a lot of storage space internally due to AOT
Works best for small storage devices Works best for Large storage devices
Stable and tested virtual machine Experimental and new – not much app support comparatively
Longer app loading time Extremely Faster and smoother Faster and app loading time and lower processor usage
Uses JIT compiler(JIT: Just-In-Time)
Thereby resulting in lower storage space consumption
Uses AOT compiler(Ahead-Of-Time) thereby compiling apps when installed
Application lagging due to garbage collector pauses and JIT Reduced application lagging and better user experience
App installation time is comparatively lower as the compilation is performed later App installation time is longer as compilation is done during installation
DVM converts bytecode every time you launch a specific app.

ART converts it just once at the time of app installation. That makes CPU execution easier. 

Improved battery life due to faster execution.

It is slower than ART. It is faster.
It does not provide optimized battery life as it consumes more power. It provides optimized battery performance as it consumes less power.
While considering Booting, then this device is fast. It lags in term of booting.

Conclusion: Which one is better

It depends on the device and one’s own device and preferences: in the long run, ART is better, but the apps do get bigger, requiring large storage space over time, unlike flappy bird which was just 1MB and required less space. Therefore, the devices in the future need to expand storage if ART is going to dominate the market in the next few years. In Android Lolipop, DVM has been replaced by ART. Because DVM converts bytecode every time you launch a specific app. But ART converts it just once during the installation of the app. That makes CPU execution easier. ARM is an architecture. Like MIPS, x86, etc. DVM/ART runs on top of ARM. Both of them can not replace each other. 


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads