Android Power User: What is JIT and What Does it Mean for Android? (Video)


JIT is one of those newfangled acronyms that are used in business today. It builds on the concept that having inventory on-hand is expensive, and in an effort to cut costs, inventory can be reduced to only that which you need “right now”. The theory follows that you order only the supplies that you need for your current production run so they’re delivered “just in time” — JIT.

In computing, it’s not that different. Just-in-time compilation (JIT) — sometimes called “dynamic translation”, is one way to improve the performance of apps at runtime — but how it does so is a little confusing. To understand it all we have to look into programming languages and how programs are run, but we’ll keep it high-level so we won’t lose anyone in the jargon.

Programming Languages

When a developer writes a program they do so using a programming language. The languages include, but are not limited to, C#, C++, Objective C, Java, Pascal, Visual Basic, ADA, Fortran, etc. Each language is different. Each has different syntax, different libraries, and different pros and cons. None of them are the actual code that computers, smartphones, and tablets run. Why? Programs need to be “compiled” to run.


My Code's Compiling

When my code is compiling, I prefer Laser Tag

“Modern programming languages” are much easier to program in than earlier languages, and don’t even get me started on programming in “native code”. I can do today in one day what it would have taken me a week to do previously. Why? Modern programming languages have libraries, helper classes, and syntax that are all much more helpful and do a lot of the work for you.

Sure, that sounds “lazy”, but why re-invent the wheel?  Modern programming emphasizes code re-use over code duplication. Code written this way is much easier to support and maintain, and when done right, can greatly accelerate the development cycle.

The downside to compiling? You have to compile  your code before you can run it. Compiling takes time, as illustrated by the XKCD comic above. What’s more, compiling is specific to the platform upon which the code will be run. Oh snap, there I go with the jargon!

Programs have to be compiled specifically for different processors. Some of you may remember back in the Windows Mobile days when developers had to release their apps in two or three different versions, depending on the CPU your smartphone was running (StrongARM, MIPS, etc.). The app was the same, but the compiled code was different.

What does any of this have to do with Android?

For some time now, Android has used a JIT approach to running their apps. Even before then, Android compiled apps at runtime. Yes, that’s right! Your apps are sitting essentially uncompiled on your phone or tablet, just waiting to be run, at which time they’re compiled, saved into RAM, and executed. If that sounds complicated and slow, you’re right, it is. In the industry we call that “lag”. Lag is when you tap an icon, then have to wait for something to happen.

The solution? Precompile everything! Unfortunately, that has some downsides, too… compatibility between versions of the OS and various devices being among the more notable reasons.

Yay! We finally get to learn about JIT!

JIT compilers run apps in sort of a hybrid of compiled and uncompiled code. When run, translation into compiled code occurs continuously, and the resulting compiled code is cached to minimize slowdowns. Put simply, code can be left uncompiled until it’s needed, then, just in time, it’s compiled, cached, and ready to run.

There are other advantages to JIT over precompiled code, like handling of late-bound data types and the ability to enforce security guarantees. Those are a bit beyond the scope of this discussion.

There’s another advantage to the way Android does things: if a manufacturer wants to change processors in one of their new devices, say from ARM-based chips like the Tegra or Snapdragon families to something else, like an Intel-based CPU, with Android all you need is a custom version of the OS (including drivers and JIT compiler), and you’re done. All the apps in the Play Store will still work, even though you’re running them on a different platform.

The nuts and bolts behind this have to do with something else, of which JIT is a part, but we’ll get to that in an upcoming episode of Android Power User!

Image Credit: (cc) aldenjewell
Comic: XKCD #303 Compiling

What's your reaction?
Love It
Like It
Want It
Had It
Hated It
About The Author
Joe Levi
Joe graduated from Weber State University with two degrees in Information Systems and Technologies. He has carried mobile devices with him for more than a decade, including Apple's Newton, Microsoft's Handheld and Palm Sized PCs, and is Pocketnow's "Android Guy".By day you'll find Joe coding web pages, tweaking for SEO, and leveraging social media to spread the word. By night you'll probably find him writing technology and "prepping" articles, as well as shooting video.Read more about Joe Levi here.