What are the differences between Dalvik and ART?

What are the differences between Dalvik and ART?

Our computer only understands the Machine level language but we write code in some High-level language. Same is with Android also, in Android, your Java classes will be converted into DEX bytecode and this DEX bytecode format is translated to Machine code with the help of ART or Dalvik runtimes. After that, the Android will run the Machine code. But the question that arises here is that, what is this Runtime?

So, you can think of Runtime as a software that is used to convert the High level language in to Machine level code i.e. in Android, if you are writing some Android code in Java or Kotlin then this runtime will be used to convert the Java or Kotlin code in to Machine level code and the Android system uses this Machine code. Android uses two types of runtime i.e. Dalvik and ART. So. let’s have a look at these two.

What is Dalvik?

Dalvik is a Just In Time (JIT) compiler. By the term JIT, we mean to say that whenever you run your app in your mobile device then that part of your code that is needed for execution of your app will only be compiled at that moment and rest of the code will be compiled in the future when needed. The JIT or Just In Time compiles only a part of your code and it has a smaller memory footprint and due to this, it uses very less physical space on your device.

Following shows the flow of execution of DVM:

What are the differences between Dalvik and ART?

What is ART?

ART or Android Runtime is an Android runtime that uses Ahead Of Time(AOT). By using AOT, what is does is it converts or compiles the whole High-level language code into Machine level code and at the time of installation of the app and not dynamically as the application runs(like in case of Dalvik). By compiling the whole code during installation results in no lag that we see when we run our app on our device. By doing so, the compilation becomes very faster. Following are some of the words about ART from the Android Developers website:

ART is a new Android runtime being introduced experimentally in the 4.4 release KitKat. This is a preview of work in progress in KitKat. It is available for obtaining early developer and partner feedback.

Following shows the flow of execution of ART:

What are the differences between Dalvik and ART?

Difference between ART and Dalvik

  1. Approach: ART uses AOT(Ahead Of Time) approach and compiles the whole code during the installation time but the Dalvik uses JIT(Just In Time) approach and complies only a part of the code during installation and rest of the code will be compiled dynamically.
  2. Booting time: As compare to Dalvik, ART takes more time to reboot because the cache is built at the first time. So, the booting is slow.
  3. Space: Since ART uses the AOT approach, so it needs more space during installation. While Dalvik uses the JIT approach, so for mobile phones having less storage can use the Dalvik.
  4. Battery: ART increases battery performance to a large extent because of the AOT approach. While the Dalvik uses the JIT approach and this results in more battery utilization.
  5. Garbage Collection: ART has better garbage collection than Dalvik.

So, DVM uses JIT and have a lot of drawbacks that were replaced by ART. So, from Android 4.4(Kitkat) ART was introduced as runtime and finally from Android 5.0(Lollipop), the Dalvik was completely replaced by ART by Android.

Benefits of using ART over Dalvik

  1. The application will run faster as compilation is done during installation only.
  2. Performance of the battery will be increased by using ART.
  3. The garbage collection is also improved.
  4. As the native code is directly executed, ART reduces the startup time of applications.

Drawbacks of ART

  1. Since the compilation of the code is done once, ART requires more space or storage during installation.
  2. The booting time is more as compared to Dalvik because it uses the concept of AOT.

Conclusion

If you are using ART, then you must have felt the difference while using the application i.e. by using ART, you will see a huge improvement in the speed and smoothness of your Android application. ART is still under development and many new features are being added to ART to give a better experience of Android to users and Android developers.

That’s all for this blog. You can read some more blogs on Android by visiting our MindOrks blog website .

Keep Learning :)

Team MindOrks!