Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between AOT and JIT compiler in the ART

In Marshmallow there was an AOT compiler added with ART. From Android N another compiler JIT was added in addition with AOT.

What are AOT compiler specific job/features and what areJIT compiler job/features?

like image 873
0xAliHn Avatar asked Oct 31 '16 04:10

0xAliHn


People also ask

What is the difference between AOT compilation and JIT compilation?

Just-in-Time (JIT) is a type of compilation that compiles your app in the browser at runtime. Ahead-of-Time (AOT) is a type of compilation that compiles your app at build time.

Does art use JIT?

Android runtime (ART) includes a just-in-time (JIT) compiler with code profiling that continually improves the performance of Android applications as they run.

What is AOT compilation What are the advantages of AOT?

The Angular ahead-of-time (AOT) compiler converts your Angular HTML and TypeScript code into efficient JavaScript code during the build phase before the browser downloads and runs that code. Compiling your application during the build process provides a faster rendering in the browser.

Is AOT faster than JIT?

In theory, a Just-in-Time (JIT) compiler has an advantage over Ahead-of-Time (AOT) if it has enough time and computational resources available. A JIT compiler can be faster because the machine code is being generated on the exact machine that it will also execute on.


1 Answers

In Android Java classes converted into DEX bytecode. The DEX bytecode format is translated to native machine code via either ART or the Dalvik runtimes.

Dalvik is a JIT (Just in time) compilation based engine. There were drawbacks to use Dalvik hence from Android 4.4 (kitkat) ART was introduced as a runtime and from Android 5.0 (Lollipop) it has completely replaced Dalvik. Android 7.0 adds a just-in-time (JIT) compiler with code profiling to Android runtime (ART) that constantly improves the performance of Android apps as they run.

(Dalvik used JIT (Just in time) compilation whereas ART uses AOT (Ahead of time) compilation.)

Just In Time (JIT):

With the Dalvik JIT compiler, each time when the app is run, it dynamically translates a part of the Dalvik bytecode into machine code. As the execution progresses, more bytecode is compiled and cached. Since JIT compiles only a part of the code, it has a smaller memory footprint and uses less physical space on the device.

Ahead Of Time (AOT):

ART is equipped with an Ahead-of-Time compiler. During the app’s installation phase, it statically translates the DEX bytecode into machine code and stores in the device’s storage. This is a one-time event which happens when the app is installed on the device.

Android N includes a hybrid runtime:

There won’t be any compilation during install, and applications can be started right away, the bytecode being interpreted. There is a new, faster interpreter in ART and it is accompanied by a new JIT, but the JIT information is not persisted. Instead, the code is profiled during execution and the resulted data is saved.

Benefits of ART:

  • Apps run faster as DEX bytecode translation done during installation.
  • Reduces startup time of applications as native code is directly executed.
  • Improves battery performance as power utilized to interpreted byte codes line by line is saved.
  • Improved garbage collector.

Drawbacks of ART:

  • App Installation takes more time because of DEX bytecodes conversion into machine code during installation.

  • As the native machine code generated on installation is stored in internal storage, more internal storage is required.

like image 61
Mitesh Vanaliya Avatar answered Oct 03 '22 06:10

Mitesh Vanaliya