The work on Android ART started in June 2016 and its main aim was to replace the incumbent Dalvik runtime. Dalvik was meant to optimise for memory as the mobile phones of older generation had low RAM sizes which could not handle the big chunk of entire app compiled code. Dalvik Runtime was based on JIT or Just in Time compilation, ie, as and when the user navigated through the app the code of the app would be compiled at runtime. This had resulted in some inefficiencies, since the code would be compiled at runtime, there was a delay in compiling and then loading the executable code which made apps a little slow to respond and also resulted in higher battery usage. But, with newer mobile phones that had larger RAM sizes it was time to come up with a technique to take advantage of big RAM sizes for eg. to compile the entire code before hand. ART was introduced as a replacement to Dalvik which would be initially based on AOT or Ahead Of Time Compilation in Android Lollipop which meant that at install time the android system would compile the entire app code and make the executable code ready even before the app would run on a mobile phone. This would result in faster app performance. Also, JIT could do only local optimisation as it had only a small chunk of code at its dispense whereas AOT would see entire code at once so it could do a lot of optimisations before hand. ART didn’t start completely fresh and actually reused a lot of code and tests that were written for Dalvik

Since the entire compilation was done at install time AOT had two cons:- It resulted in longer install times and also it meant that the code which was rarely used would also be compiled ahead in time which was not very useful.
So, by the time Nougat was released the Android team decided to come up with a hybrid of AOT and JIT called profile guided compilation for ART. Android would now monitor the pattern of usage of app and will make a profile of which features are used more in the app. Based on the usage statistics it would decide what needs to be compiled Ahead in Time and what Just in Time. So something which is hot ie used often would be compiled before hand and what is used sparingly would be compiled Just in Time. Initially, ie for the first few launches of app, the app will be fully JIT and as and when the profile for hot features is built AOT will be used for hot features. So initially till the profile is built the app may start a little slow but later it would run faster. The profile would be kept on both cloud – per app version and per manufacturer model and also locally on mobile which would be based on user specific patterns.
Image Credits:
Leave a Reply