When the Huawei P30 was released this year, Huawei also released a compiler called “Ark”. But many people actually misunderstood what the ARK compiler was all about. Today we will talk about Huawei ARK compiler in detail. To be really clear the ARK compiler is not a separate operating system. It’s a tool for Android!
Table of Contents
The advantages of the Ark compiler can be summarised as follows:
1. Android program compilation performance is better with the Ark compiler.
2. Android program installation speed is faster using the Ark compiler.
3. Android programs run faster when Ark compiler is used.
4. The system garbage is managed efficiently. The dependence on powerful mobile phone hardware is reduced.
5. Extremely power saving compared to the conventional approaches.
Android and Java
From the beginning to the present, most of Android’s programs are written in Java (also C). Java is one of the most powerful computer languages in the world. But if you know the principles of computers, the CPU of a computer only accepts assembly commands. So how can we make the CPU understand the Java language program?
If you use an intermediate layer that interprets Java as an assembly language and acts as a “translator”, then it becomes a Java program. This explanation shows how inefficient this whole process is.
So can you turn Java directly into machine-driven assembly code?
Yes, there are two ways, one is to compile the code before the program is executed, this is called Ahead of time, referred to as AOT. The other method is to compile after the program is run, called Just in Time, JIT.
In the early days of Android, before Android 5.0, Android phones had problems with memory. The whole experience was slow and sluggish and often criticised by users.
Why was this happening? Simply because Android used the middle layer + JIT garbage mode, this mechanism wasn’t fast, and garbage collection was also a problem at that time. It was slow and hence the whole user experience became slow. This method also wasted a significant amount of battery life.
In the period of Android 5.0-6.0, Google configured ART (Android Runtime) for Android, this time it was the full AOT mode. But it also had its own problems.
Because it was compiled before execution, the installation speed was very slow and very space-consuming. It should be known that the 64 GB storage on mobile phones at that time was considered to be a large capacity. And the AOT must be executed once after the boot and restart. So the speed was very slow and the user experience did improve. This is why the memory and capacity of Android phones have grown from the previous two years. All the Android phones these days have inflated RAM capacities and storage options just because of this.
The state of Android now?
After Android 7.0, Google also realised that the programs occupied quite a lot of space, the boot time was also slow and something needed to be changed.
Google found that people use some programs routinely and not everything all the time. So it was considered efficient to compile a part of the commonly used ones only.
So at this time, Google is actually pulling the JIT back to Android. And it is not necessary to fully compile something when installing. It is installed directly, and the speed is, of course, faster this way!
This is actually the middle layer, JIT and AOT have come together. And according to the user’s habits, the commonly used function code of the commonly used program is compiled and saved. This leads to faster user experience.
After Android 7.0, what Google has been doing is optimisation. The 8.0 system is an interpreter that speeds up the interpretation of “cold code.”
The latest 10.0 (Android Q) system, even at the time of installation, knows in advance if a program is commonly used by the user. The installation time is slightly longer. But the stuff which would really be important would already be compiled, further improving the speed.
Why is Huawei Ark compiler optimised or better?
Looking at the above, we know that Google’s solution is actually not that efficient. So what is Huawei doing?
In fact, Huawei’s ARK compiler fixes some problems in the depth of the soul of Android. From the beginning of program development to the packaged APK, it is directly using the assembly instruction (binary code) that the mobile phone CPU can understand, which improves overall efficiency.
In the Ark compiler, the compiled APK will be converted to machine code and then installed by static compilation. This is actually AOT, and hence there’s no need for the troublesome virtual machine, thereby improve running speed and efficiency.
And as a developer, you can also choose different compiler optimisation schemes according to different program features, unlike the official virtual machine scheme of Android.
Nowadays, a major feature of Android phones is that the RAM is reaching ever increasing sizes. 6 GB of RAM has become normal for flagship smartphones these days. And then there are smartphones like the OnePlus 7 Pro with 12 GB of RAM and such!
Efficient Garbage Cleanup?
In addition to the large programs, there is a relationship between the running of Android programs and the generation of garbage. So how to clean up the garbage? Then you need to pause the program, and then the whole process would happen.
The Huawei Ark compiler is characterised by the use of multi-threaded programs. For example, any app you are using now uses two threads A & B. In Huawei’s P30 smartphone, when thread A runs, B cleans up the garbage, and then A thread cleans up the garbage when B thread In operation. This way the program runs without interruption, garbage disposal does not stop, and it is coherent and saves system resources.
Another great thing about Huawei is that they are not going to make the ARK compiler their proprietary product! In August of this year, Huawei will make the source code of the Ark compiler public. At that time, many smartphone companies can start to use the efficient and resource-saving Ark compiler to bring a better mobile phone experience without giving up on Android.
So guys what do you think about the Huawei ARK compiler? Do let us know your views in the comments section below!
Keep visiting for more such awesome posts, internet tips, gadget reviews, and remember we cover,
“Everything under the Sun!”