Dedicated Runtime Thread (ART vs Dalvik)

aeppacher

Senior Member
Apr 14, 2012
792
777
93
Okay guys,

with the introduction of 4.4 kitkat, Google decided to include ART as an optional second runtime that can be enabled through developer options. Naturally when promised faster app launch times, people will turn it on. ART is not stable however and so problems will be occur. For this reason, in hopes to prevent kernel developers, rom developers, and android developers from having their thread hijacked, I am making a thread dedicated to runtimes here. DO NOT POST ABOUT THIS TO DEVELOPERS ON THEIR THREADS, bugs when you are running ART are not their fault.


What is Dalvik?

Dalvik is the process virtual machine (VM) in Google's Android operating system. It is the software that runs the apps on Android devices. Dalvik is thus an integral part of Android, which is typically used on mobile devices such as mobile phones and tablet computers as well as more recently on embedded devices such as smart TVs and media streamers. Programs are commonly written in Java and compiled to bytecode. They are then converted from Java Virtual Machine-compatible .class files to Dalvik-compatible .dex (Dalvik Executable) files before installation on a device. The compact Dalvik Executable format is designed to be suitable for systems that are constrained in terms of memory and processor speed. Dalvik is open-source software.

Dalvik is named after an Icelandic city.
(source)

Okay so what is ART?

ART is a project Google has been working on for reportedly for 2 years. The goal of ART was to produce a faster runtime that wouldn't suffer from the problems Dalvik suffers. Android Kit Kat 4.4 is the first operating system with ART included in developers options although it is unclear just how recent this version is.

ART stands for Android RunTime
(source)

Great, Whats the Difference Then?

The main difference between ART and Dalvik is when they compile app code. Dalvik operates under a JIT (Just In Time) compilation method which means that when developers make their apps, they partially compile their code into bytecode which is interpreted by the java virtual machine. Dalvik converts bytecode to machinecode as the app runs to increase performance (bytecode execution is slower than machinecode execution). ART differs from Dalvik by performing this compilation of bytecode to machine code at installation of the app and saves this to the phones storage (not ram).
(source)

So Why Use ART?

Using ART instead of Dalvik allows the system to use much less resources during runtime. When apps are running, interpretation of bytecode is not ongoing, this can reduce CPU load and RAM usage. The resulting effect is faster app startup times (reportedly almost twice as fast) and better in app performance.

It should be noted that performance boosts will only really improve for the java components of apps. Apps like games which rely on the NDK or other languages will receive more incremental experience boosts.
(source)

Why Shouldn't I Use ART

Well first and foremost, Google's documentation of ART suggests not using ART because it can cause app instabilities and an unstable android implementation all together. It is still largely in development and it is unknown just how recent the version included in the current kit kat build is. Google is introducing it to the development community but really doesn't intend users to use it as a daily runtime.

Also since ART precompiles and saves that precompiled code upon installation of apps, it takes up more storage. The increase is about 10-20% of the code in the application. Remember the majority of apps usually comprises media files such as images, videos, sounds... so those components will be unaffected. For example, the Google+ apk is about 28Mb yet the code is only comprise of 7Mb. The increase in storage size is nominal, but worth noting.

Also the first start up after enabling ART can take up to 10 minutes due to this compilation occurring. Installation of apps will also take slightly longer but with hardware on the Nexus 5 you are unlikely to even notice.

ART also can cause issues with app backup and restoration.
(source) (source)

Custom Roms and ART

As developers start building Kit Kat roms from source they will have to decide if they would like to include ART in their builds. Google has created a flag to include ART in addition to Dalvik. This is a simple implementation, but if threads keep getting hijacked by discussions of ART and bugs, I wouldn't be surprised if developers choose to exclude ART from their builds.

ART also cannot function with deodexed apps. The odex files are necessary for bytecode to machine code compilation. Flashing a deodexed ROM or gaps with ART enabled will produce force closes and crashes to the point the UI won't be functional.

Also initial setup between Roms will take longer with ART since performing a factory reset as well as clearing caches will clear the stored precompiled code that ART saves. Dalvik will always be enabled at start up, so switching to ART will require a reboot and a wait for set up.
(source)



In my synopsis of ART and Dalvik I may have made a mistake or two or not explained something properly. If you spot a mistake or would like clarification, simply post and I will modify the OP.

Please, please, please send people to this thread if they are asking about runtimes in a developers thread. Having had my kernel thread hijacked by unrelated issues that are outside of my control, I understand the pain.
 
Last edited:

aeppacher

Senior Member
Apr 14, 2012
792
777
93
I will not be posting a complete list of apps broken by ART, it would take way too much time and this is likely to change as the developers get to update their code to be optimized on 4.4. You are welcome to post any issues, but its pretty much ART can break a lot of apps.
 
  • Like
Reactions: mw86

aeppacher

Senior Member
Apr 14, 2012
792
777
93
I find app compatibility remarkably high. I have over 60 apps installed and the only ones that aren't working is titanium backup and greenify.

Everything else works even games like asphalt 8 and pvz2.
Games generally are not coded in Java (usually NDK or something else) and so they will be effected much less by ART than other apps.
 

aliwho

Senior Member
Nov 26, 2011
334
101
0
I thought that the play store felt noticeably faster when using ART when I was installing a bunch of apps last night.

Titanium backup and whatsapp instability are huge deal breakers for me, unfortunately.

Sent from my Nexus 5 using XDA Premium 4 mobile app
 
  • Like
Reactions: phillipm

agalvin13

Senior Member
May 16, 2012
358
55
0
I find app compatibility remarkably high. I have over 60 apps installed and the only ones that aren't working is titanium backup and greenify.

Everything else works even games like asphalt 8 and pvz2.
greenify seems to be working fine for me with ART. What problems are you experiencing?
 

miHah

Senior Member
Jun 12, 2011
388
251
0
Ljubljana
www.dinozavri.info
Hi,

I know this may sound really stupid but.. can you guys write down some of your most used Apps that are written in Java? Do you notice any performance improvement?

Also, does ART affect overall android experience (original apps, launcher).


I am no developer and I don't know much about computer languages (so please don't throw rocks at me for those questions) but I like to tweak my phone to see what seems to be the best for my phone.
 
Last edited:

agalvin13

Senior Member
May 16, 2012
358
55
0
Does ART affect battery life?

Sent from my Nexus 5 using Tapatalk
It theoretically will and could. I haven't noticed a markable increase in battery life so far though. One would have to perform some test but scrolling and apps loading seems more fluid imo. I am leaving it on.
 
  • Like
Reactions: busab

aeppacher

Senior Member
Apr 14, 2012
792
777
93
Does ART affect battery life?

Sent from my Nexus 5 using Tapatalk
Theoretically, yes since it attempts to decrease cpu load and ram usage at runtime, it should theoretically give you some better battery life. But battery life is hard to gauge, so don't expect any definitive results on that anytime soon.
 
  • Like
Reactions: busab

aeppacher

Senior Member
Apr 14, 2012
792
777
93
I know this may sound really stupid but.. can you guys write down some of your most used Apps that are written in Java? Do you notice any performance improvement?

Also, does ART affect overall android experience (original apps, launcher).


I am no developer and I don't know much about computer languages (so please don't throw rocks at me for those questions) but I like to tweak my phone to see what seems to be the best for my phone.
Pretty much all apps that are regular run of the mill apps will be coded in Java. It is just intensive programs like games are generally coded using the NDK, but all other apps in large will be in java (the vast majority).

When you say original apps, I assume you mean system apps like the GE Launcher, or settings app. These are all coded in java so yes they will get improvements too.

EDIT: if you want what is best for your phone, stick with dalvic, it's more stable.
 

aletto

Senior Member
Jul 14, 2011
174
47
0
Something I noticed with the Nexus 4 (Dalvik, obviously) is that if you have a lot of apps (10+ maybe?) open, the recent apps will take a slight delay to show up. It isn't lag, but it even appears with the Nexus 5. If you switch to ART, the recent apps will show up immediately, no matter what. I'd say that alone would be worth it to switch to ART, it makes everyday use feel notably smoother.
 

Shardzmi

Senior Member
Dec 4, 2012
346
150
0
Something I noticed with the Nexus 4 (Dalvik, obviously) is that if you have a lot of apps (10+ maybe?) open, the recent apps will take a slight delay to show up. It isn't lag, but it even appears with the Nexus 5. If you switch to ART, the recent apps will show up immediately, no matter what. I'd say that alone would be worth it to switch to ART, it makes everyday use feel notably smoother.
I agree - the bad part is that it breaks tibu and whatsapp. Why can't devs be a bit more on their toes when an update comes ? :(
 

Nastybutler

Senior Member
Nov 18, 2012
500
216
0
Anchorage
Been running ART for a full day now, and aside from TB, I've had no issues. Greenify works fine, and I don't use Whatsap, so hopefully by the time custom ROMs that support ART come out, TB will be updated to fix this issue. If not, oh well. I'll stick with it for now seeing as how much better some notoriously slow and crappy apps are running. Maybe it's just a placebo, but I've never seen the Facebook app load so quick and scroll so smoothly as it does now.