ART runtime for Kitkat 4.4 explained.

Standard

Android 4.4 KitKat ushers in several new and exciting features with the new Nexus 5 (and further updates from Google to other Nexuses too). One of the most exciting,underdeveloped feature is a Real time compiler engine ART which has caught many eye balls in the media and among the developer community recently Some say that its due to Google new purchase start-up Flexycore is the reason behind but seeing the commits in the AOSP tells a different story that google was developing it even before the launch of Nexus 4 and So, Flexycore has nothing to do with it until recently when they joined Google for improving the ART run time. In simple words its a near replacement to today’s used Dalvik VM run time, the software responsible for all apps working in Today’s Android Phones

What is ART ?

ART stands for “Android Runtime” written in C/C++ native language which Google claims to replace the way apps are fundamentally handled by Dalvik.The dalvik runtime uses Just-In-time (JIT) compilation method to interpret the bytecode ,a exclusive version of the application code.So if you want to understand this, its like the apps written by developer are partially compiled and build, now this compiled file is ran through a device and its decoded every time it is ran on the device.This process is cumbersome and also not so efficient (though it is used in this way only for now) but the only advantage of this thing to be used is that it allows it to run on variety of Hardware platform ( wiz. ARM,x86 )unlike other platforms like iOS,Windows(to some extent) without developers needing to do anything extra for making it run on other platforms(and this is great).Also ART requires 50% less time for app startup.

Readwrite has a better example to make it understand for people:

Imagine: every time you open an app, all the different parts of the smartphone responsible for making that app work have to scramble to assemble the code for the app to make it work on your device. You close the app and all those parts relax. You open it and they scramble again. This is not a very efficient way to run apps but it allows those apps to run basically anywhere (what dalvik does)

How does ART work then ?

ART doesn’t work anything differently like what we call it in India as Rajnikanth thing ( translate : a task impossible to perform).ART uses a new approach to set-up this task it pre-compiles this task and converts it into Low level Machine language (simplest form a machine understands code) when they are first installed .This pre conversion is called as Ahead-of-Time(AOT) compilation techique which allows the apps to be truly native apps when they are installed during first BOOT (first installation takes a lot of time).At present though its in developing stages and Google warns it to users to use only if you want to risk your phone and stil keep dalvik as your default runtime only (if you run 3rd party-apps).ART can be switched on from

Settings -> Developer options -> Select runtime

Remember first BOOT can take seriously 10-20 minutes to complete as ART converts existing Dalvik runtime (libdvm.so) to the ART compatible  (libart.so) and also   rather than the ODEX files read by the Dalvik VM, ART appears to use OAT files you can even find file on AOSP.

Android Police Cody toombs:Warning: Do not try this with the Paranoid Android (or other AOSP) build right now. There is an incompatibility with the current gapps package that causes rapid crashing, making the interface unusable and also explains that :

For now, the potential gains in efficiency are difficult to gauge based on the version of ART currently shipping with KitKat, so it isn’t representative of what will be possible once it has been extensively optimized. Thus far, estimates and some benchmarks suggest that the new runtime is already capable of cutting execution time in half for most applications. This means that long-running, processor-intensive tasks will be able to finish faster, allowing the system to idle more often and for longer. Regular applications will also benefit from smoother animations and more instantaneous responses to touch and other sensor data. Additionally, now that the typical device contains a quad-core (or greater) processor, many situations will call for activating fewer cores, and it may be possible to make even better use of the lower-powered cores in ARM’s big.LITTLE architecture. How much this improves battery life and performance will vary quite a bit based on usage scenarios and hardware, but the results could be substantial.

 

ART actually has two compiler backends, both Ahead-of-Time. And one of them is based on LLVM! (The new rock star in the world of compilers) LLVM(which allows machine language code to be understood), with its more modular design, has managed to evolve at a very fast rate and take on the big guns (GCC, cl.exe) in a very short amount of time. Although most of LLVM’s strengths seem inapplicable here. ART is awesome Strikes a good balance between portability and performance,but ART is not very innovative. There also have been many successful attempts at speeding up Dalvik in the past but failed to do

(P.S:The phrase “Ahead-of-Time” is unnecessary, but when talking about JIT on already compiled code, simply saying “compiling” can be confusing, so AOT hence the redundant phrase.)

So is Dalvik bad?

Answer: Yes(to some extent) but limitations and reason are as follows:

  • Dalvik isn’t slow because it is bulky or outdated. It is slow (if you really want to call it that) because it’s a VM. Every VM incurs an overhead simply because of the added layer.The best VMs today can run code at 2X(slow) w.r.t native and so does Dalvik
  • Android isn’t slow due to Dalvik.Android is laggy(in use) more because of its massively multitasking nature,and because apps abuse and hog the system and battery (I’m looking at you Facebook)

(Note: if you hate apps hogging up your phone, but can’t live without fat apps, look into Greenify. Requires root though)

  • JIT compilation is great, JIT compiler is awesome, JIT compilation technique hardly affects 2% of the code.That 2% being really busy code, which hurt people a lot
  • As mentioned above, You can’t have pre-compiled Android app binaries, simply because Android isn’t a single,unified runtime (like iOS or Windows Phone).Android runs on all sorts of hardware (more differentiation than just arm v7, v7a, v8… x86)and for different instruction sets There has to be a single, unified byte code that gets translated to hardware specific code after install and  Dalvik is the best for that(untill ART arrived).ART’s benchmarks show 2x speed improvements. Note that Dalvik is 4x slower than native, although the gap isn’t noticeable in regular use,atleast for opening and using apps
  • Some one xda actually made a benchmark test: here is the result
  • Image

What does this mean to developers?

  • Thanks to Google, developer workflows shouldn’t change. Current developer workflow doesn’t involve dalvik anyway. As long as ART is able to read bytecode for dalvik, in other words, as long as ART doesn’t necessitate a new bytecode format (which it does till now), app developers shouldn’t have to worry a thing but you never know
  • One drawback of AOT Compiling is that developers will start to get bug reports that they can’t reproduce due to issues with compiling for a specific architecture. So developers will need to test apps on more device(like what Facebook did in a Google Lab with 70 Phone)
  • Apps will still be developed in Java and distributed as Java bytecode in apks. So no separation from Oracle technologies there.
  • AOT frees the developer from having to compile for all current and future architecture, while precompiling would require very fat binaries
  • Any language with an LLVM front end could be used to develop apps with ART(not just a language limitation) . I’m especially excited about this.
  • Native code is the best way to go but native code can be more dangerous. Programmer has more control, meaning dumb programmers can damage your phone.
  • ART will have JNI capabilities .JNI is an interface to native code from Java. The key point to take away is that JNI is for calling on code that was written to be native from the start, and therefore enjoys further optimization. Obviously, I’m simplifying quite a bit, but this is the basic.

What about custom Recovery dalvik cache?

  • Dalvik cache is that, By definition that means that anything put there can be wiped to make room for some other stuff (another app that needs to run) so when you run again the original app the JIT compiler acts again.I would think that ART won’t work this way and store complied apps in a more permanent fashion, aka the more space needed (Nexus watch out)        So, for using the ART cache the custom recovery(like CWM ,TWPR ) will need to optimise it to clear the ART Cache also (if only ART is default Runtime)

What do we lose from Dalvik?

  • ART compiles to machine level language and hence requires much more space for storage

To explain this will take an example: it’s like a zip file where the apk is the .zip file and after extracting the zip what we get is the machine level code.So here zip is what dalvik used to run directly but ART needs the extracted (here machine level code) before hand to run and this can go upto apps using up 200% more space than what dalvik used to run it.

  • When an App is first installed it needs time to convert to ART runtime format and this takes time ( not if its for a single app). But for the whole system apps it will require patience .Imagine you have 150-200 right now and you change to ART runtime ,then it seriously tests your patience( at least 20-30mins required ,as mentioned above)

Final thought:

ART sounds like a pretty amazing project, one that I hope to see as a regular part of Android sooner rather than later. Improvements are likely to happen and it will get better and will surely reduce lag and you won’t again think that an iPhone with 1 GB RAM is smooth than a Samsung S4 with 2GB RAM( native support will change it).

The Optimized code, pre compiling , better runtime  can all together work out and in the end improve the Battery Life cause at the end what Matters is Battery Life of a Phone

 

 

   


The official google documentation may vary a little bit from this information

Disclaimer :All the Thoughts and opinion mentioned above are just only my opinion,any resemblance to anyone is not intentional

 

Advertisements

Buying Nexus 5 From US Play Store to India under Rs. 26000

Link

 Nexus 5 was launched today and it will be atleast a couple of months before it arrives in India. So, if you want to order Nexus 5 immediately from US play store, this is the ultimate guide you need to follow.

And the best part is, ordering from US play store will not only get you Nexus 5 much earlier, but you will actually end up saving good amount of money compared to buying it from India.

Follow the guide given below, and you should not have any problems.

Google Nexus 5 INR Price if you Order in India from US Play Store

[Price calculated at Rs. 62 exchange rate]

  Nexus 5 (India)16 GB Nexus 5 (US)16 GB Nexus 5 (India ) 32GB Nexus 5(US) 32 GB    
Prices INR 28,999 USD 349 INR 32,999 USD 399    
Shipping   USD 37   USD 42    
Shopandship INR 0 INR 620   INR 620    
Import Duties +Octroi(optional to maharshtra,so exclude from total ) INR 0 INR 1200-1300   INR 1200-1300    
Total INR 28,999 INR 25,105 INR 32,999 INR29,109    

Note: The prices may vary slightly depending you are address in the US as taxes differ from state to state.

Link to :Custom Duties Prices

Please keep in mind that guide below was prepared for Buying any Product from US, the process is exactly the same for Nexus 5

If you follow me on Twitter  , by now, you know that I am a proud owner of Samsung Galaxy Nexus. It is definitely not the most expensive  out there, but when I got it for the first time, it felt like I had achieved something.. and by the end of this article you will know why I had that feeling. Nexus 5 is available in India through regular Google Play store

So 2 Reason to Buy From US:

Of course, you can buy it on 3rd party websites like E-bay, grabmore,Amazon and many other sites, but you need to pay atleast 30 to 40 percent premium on the pricing. Now, I could have bought by paying the premium, but it would not have given me half the satisfaction.of ordering it from playstore

Buying a Nexus 5 via Google play store in India is an arduous task, it really is, and it will probably remain so till the time Google decides to release it in India.I Doubt that those who aren’t Tech Savvy will Hardly Ever own a Nexus ..But this Guide will Surely help them Somehow to Simplify it,

Step 1 – Getting to Google Play Nexus  “Buy Now” page

While you can visit Google Play Nexus page by going to Nexus 5 once you click on “shop now” button, you will be first presented with a screen that says:

PS 2

The devices on Google play are COMING SOON in India, so you will need a workaround.

So the first thing to Shop the US playstore on your Browser you need to Download a VPN Client which will give you a Temporary US based IP so the Playstore understands that you have logged in from US. These VPN Clients offer Free Data of 500 MB to 1 GB Free per Month.

If you are not comfortable with VPN Clients, just search Google for a US proxy or VPN client, and you should get many others as well.

HotSpot Shield

You will need to download the VPN Client Hotspot Shield  register with them and you are ready to go. Once you have started the VPN Client, It will ask you for Upgrade Options..It your wish if you want to Upgrade you can Carry on(if you wish to use Spotify , Pandora etc  US based Service then you will surely need to Upgrade to pro)

Vpn 2

Now go to the Browser and Open the Same Site and BOOM

Nexus 5

You can opt for 16GB or 32 GB(its only USD 50 more) its upto you.But once the phone is in shopping cart, you are faced with another issue. You need to 2 things – A US Credit card with and US shipping address because Google does not ship outside of the US. So, before you actually go through the process, you will need to have these 2 things in place.

How to Get US Shipping Address

There are few online portals who offer you virtual US post box addresses. Shopandship.com, is one of the leading sites who offer you US, UK as well as China shipping addresses. I recommend you using this  to order my Nexus 5. I have been recommended by one of my members here  for Choosing shopandship

However, please note that you will need atleast a week for your account to get activated and your shipping address being assigned to you. So, before you head to the Google Play store, please make sure that you have your US shipping address in place with you and you are ready to give it a go

In regards to the US credit card, there is a workaround. You can use your Indian Credit card itself(sometimes it works ,Sometimes it doesn’t) and for billing address, you can give any US address. ;I gave US address of my Friend studying there

If you don’t have a credit card and have a debit card from banks like HDFC,ICICI ,AXIS Bank they offer virtual netsafe credit cards to be generated, which could be used!

Alternate:You can go to this Website for getting a Virtual Debit Card for US or This also work ( Tipped by One of my friend)

Note:This problem of Virtual Debit card only Occurs for PlayStore and not for sites like Amazon,Ebay

Placing the Order on Google Play

Coming back to placing order on Playstore. Once you have selected the Nexus 5 model 16 GB or 32 GB and entered the shopping cart, enter you credit card and US shipping address and in all probability your order should get through.[OT]One of my Friend who placed an Order on 1 Nov 2013 from India had a email saying that it will Leave the Warehouse by 5 November by Luckily his Brother Stays there and he will Ship it to him via International Courier

Additional Charge of 20 USD to 30 USD( approx INR 1240 to 1860) [/OT]

India Shipping, Customs & Duties

Luckily Shopandship and PPoBox does everything on your behalf.Once they receive the Product on mY behalf on the Virtual Address. they will Weight the Product and Accordingly Charge me the Shipping Rates

Luckily Nexus 5 is 130 g (4.59 oz) so the Shipping Charges are Minimal ( INR 600-1000 )

Note: The Heavier the Product the More is the Shipping Charge

Exact Cost of Google Nexus 5

Here is the exact break-up of cost on Google Nexus 5(Rate INR 61.88)

  Nexus 5 (India)16 GB Nexus 5 (US)16 GB Nexus 5 (India ) 32GB Nexus 5(US) 32 GB    
Prices INR 28,999 USD 349 INR 32,999 USD 399    
Shipping   USD 37   USD 42    
Shopandship INR 0 INR 620  INR 0 INR 620    
Import Duties* +Octroi(Only For Maharashtra,So Exclude from total) INR 0 INR 1200-1300  INR 0 INR 1200-1300    
Total INR 28,999 INR 25,105 INR 32,999 INR29,109    

Add to this Octroi which came to about Rs. 1100 taking the cost of Nexus phone to Rs. 25,500. However, in most other cities in India, Octroi is not there. So, even with slight change in exchange rates and other things, the cost of your Nexus 5 phone should not exceed Rs. 25,500/-. For that price, Google Nexus 5 is definitely worth it!

N5 India

Image Edit: Nexus 5 Comes up on indian Retail Store

Wait for it cause this time Google is expected to Launch In India for INR 28,999 and INR 32,999 for 16 and 32 GB respectively on PlayStore .But this is Exclusive of Shipping and Taxes So ,Considering Google’s Shipping Charges (Like in US) the Price Of Nexus 5 may go beyond INR 30,000 or INR 34,000

TIP: Buy it from Amazon US and you can get a 7.5% (Monthly Coupon Code if you Buy from there frequently) off on the Nexus 5 (i.e 323$ or INR 19987 )

Like I said, it is a Difficult task buying a Nexus 5 in India… but in the end, it was all worth it and you save a certain Amount! If you have any questions, do drop me a comment if it Help and I would be more than happy to clarify it!

P.S:

  • This whole Process Might Take More than a Week …approximately 10-11 days..So Order it Now
  • This Method is Universal for all products from any Country but Play Store is Little bit Strict in this so Wrote a guide on it

Thanks to Arun Prabhudesai :whose Buying a Nexus 4 from US Tutorial helped me

Do Leave your Thoughts here: