How Huawei 'ARK Compiler' Wants To Revolutionize Android To Be More Like iOS

At the Honor 20 series new product launch conference, Huawei mentions 'ARK compiler' as a revolutionary breakthrough for the Android system.

What the ARK compiler is capable of, according to the president of Honor Zhao Ming, is making Android system comparable, or even beyond Apple's iOS, by giving it "unimaginable speed and operation space."

Here, he described ARK compiler as a golden finger.

According to Ming:

"This is an extremely huge upgrade. We have been looking forward to the Android system being able to surpass iOS. After the Honor 20 series was optimized by ARK, we have an experience comparable to the iPhone, and even in some respects we are better than it."

After the announcement, a heated debate started to spark outside of China.

So, what exactly is the ARK compiler? And how does it work?

Related: Android And IOS Memory Management, And How Are They Different

First of all, it should be understood that most Android apps are written in Java programming language, and second, CPUs of Android devices can only understand the assembly instructions, and can not directly identify the Java language of the virtual machine instructions.

In order to make the CPU to run apps written in Java, there are generally two ways to do that:

The first way, is to introduce a middle layer, which is responsible for executing Java code, and then compile the middle layer itself into assembly instructions that the CPU can understand. So the process would be: the CPU > middle layer > Java code.

The second way, is to translate the Java language directly into a machine language that the CPU can understand. This can be done by compiling the Java code directly into the machine language before the program runs, or compiling the Java language into machine language in real time to be executed.

This pattern is called JIT(Just in time) compilation.

ARK compiler

On Android operating system, code compilation must go through several stages. And using ARK compiler, Huawei is said to be capable of achieving "architecture-level optimization and significantly improve performance", and can solve the problem of android program "executing while explaining", which is called "android performance revolution" by Chief Executive Officer of Huawei Consumer Business Group, Yu Chengdong.

Before Android 5.0 officially adopted ART (Android Runtime), it uses Dalvik to interpret execution and the JIT method to execute Java code. At this stage it was the real "explain and execute" mode. But since the code was quite inefficient, and with GC (garbage collection) which was also bad, Android was very difficult to use.

In newer versions of Androids, Google launched ART to address previous Java code execution efficiency issues.

The complete AOT model is used at this stage; When the Android app is installed, all Java code is compiled into machine code in advance.

However, this pattern has two drawbacks:

  1. Installation speed is very slow. Even Qualcomm Dragons 855 may take a minute to compile a larger application in the AOT mode.
  2. The system's OTA opens up the opportunity to perform AOT operations on all applications, which can take a long time to boot.

Starting Android 7, Google improved this by making the operating system to compile only part of the code when users use the app. In short, Android 7 and up doesn't compile all the code when users only use a fraction on its functionality.

And starting Android 8, Google further improve the interpreter, to greatly improve the execution efficiency of the interpretation mode. And on Android 10, Google starts providing a way to pre-install hot code so that applications can know that common code will be pre-compiled at the time of installation.

As a result, the execution mode of the Android platform has reached a good balance between space usage, installation speed, and running speed.

However, it does not rid the premise that the app uses Java code when it is packaged as an APK.

In other words, as the APK becomes a user-configurable process, it goes through a compilation process within the Android system, which is a hurdle.

According to Huawei's interpretation, this hurdle in the existing Android, known as the Virtual Machine. Also referred to as the VM, it contains translators and compilers. With its purpose to convert Java into a machine can understand the language, this slowed down operations.

Here, Huawei's ARK compiler wants to solve this.

Android Dalvik - ART
A comparison of Dalvik and ART architectures

The biggest advantage of the Huawei ARK compiler is that it bypasses the VM.

Simply put, the ARK compiler can turn advanced language (Java) directly into machine code without having to go through the VM compiler built into the Android operating system.

According to Huawei, the application compiled by the ARK compiler was completed during the development phase, as long as it is a compiler compiled application, after the application market on the shelves, the user downloads the APK is compiled.

In other words, through the ARK compiler, the developer's app has been converted into machine-recognizable code before downloading, so it can be quickly installed, booted, and run on the phone without having to compile through the VM, or at least to some extent.

Using the ARK compiler, Huawei is bringing the compilation process forward to the application development phase, which results to a significant reduced operational burden on smartphones and Android operating systems.

And in addition to code compilation, the ARK compiler also provides a more efficient memory mechanism, which differs from Android memory.

While Android uses a centralized recycling mechanism for memory collection, the ARK compiler provides a more efficient memory recovery mechanism that eliminates the need to pause apps and recule them at any time.

The ARK compiler can also optimize codes: vecause it is compiled during the application development phase, the compiler can allow different applications to be flexible with different compilation optimizations.

And because compilation in the development environment is not limited by the performance of the phone, more advanced optimization algorithms can be used to optimize the performance of each application.

The company claims that after its processing, the application execution efficiency increased by 29 percent, the system operation fluency increased by 24 percent, the system response increased by 44 percent, and the third-party app operation fluency boosted by 60 percent.

On the other hand, EROFS File System can increase system’s random read speed by 20 percent, and saves up to 14 percent in storage to maximize the use of resources within the limited space of the device.

As with the nature of Android and for other reasons, Huawei won’t hold any usage rights for ARK Compiler. What this means, Huawei wants to keep the project open source for the industry to use. Huawei expects app developers to soon start using this new refined compiler for Android.