Search code examples
androiddalvikandroid-runtime

What is ART and DART in Android


In simple what is ART (Android run-time) and DART in Android, I read about it here but I don't really understand its importance and usage.

Also I searched here in Stackoverflow for any related question before I ask about that.


Solution

  • ART

    ART is the new Android Runtime. The idea is to replace the Dalvik Virtual Machine with an ahead-of-time on-device compiler suite called dex2oat and a new runtime environment for apps. So if you install an application, it is first compiled to native code by using one of the dex2oat compilers, for example Quick(default in 5.0, 5.1) or Optimizing (default from 6.0), and stored in a so called oat file, which is an ELF shared object. When the app is executed, the runtime loads the content of the oat file into a preinitialized app process. The advantage of AOT compilation is, that you can do state-of-the-art optimizations because it does not execute at runtime. So we get faster apps but slower installation time.

    DART

    As you gave the link to the Android Dev page, I assume you are NOT talking about the DART language but about the Dalvik Runtime.
    Dalvik is Android's bytecode interpreter (and JIT compiler) that used to interpret and optimize app code on the fly while executing it. So compared to a AOT compilation, the amount of optimization that can be done is restricted by the fact that longer optimization time slows down the actual execution of the application. Dalvik is superseded by ART in Android 5. Still, apps' code is stored as dex files which are the input format for the ART compilers. Also, for debugging purposes and for devices with low persistens memory, the interpreter is still around, even though it is not default and it might be a lighter version.