# Android CPU, Compilers, D8 & R8

DevFeed: [Android CPU, Compilers, D8 & R8](<https://devfeed.tech/articles/android-cpu-compilers-d8-r8-26131.md>)

Original publisher: [Read original article](<https://proandroiddev.com/android-cpu-compilers-d8-r8-a3aa2bfbc109?source=rss-8735065c2497------2>)

Author: Yonatan (Yoni) Levin

Published: 2019-03-18T06:27:24Z

Content type: article

Language: en

Sources: [Yonatan V. Levin](<https://devfeed.tech/sources/stories-by-yonatan-v-levin-on-medium.md>)

Topics: [R8](<https://devfeed.tech/topics/r8.md>), [Android](<https://devfeed.tech/topics/android.md>), [Compilers and Linkers](<https://devfeed.tech/topics/compilers-and-linkers.md>), [Gradle](<https://devfeed.tech/topics/gradle.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-architecture](<https://devfeed.tech/tags/android-architecture.md>), [android-development](<https://devfeed.tech/tags/android-development.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [aot](<https://devfeed.tech/tags/aot.md>), [architecture](<https://devfeed.tech/tags/architecture.md>), [architectures](<https://devfeed.tech/tags/architectures.md>), [arm64](<https://devfeed.tech/tags/arm64.md>), [build-system](<https://devfeed.tech/tags/build-system.md>), [bytecode](<https://devfeed.tech/tags/bytecode.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [caching](<https://devfeed.tech/tags/caching.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [compilers](<https://devfeed.tech/tags/compilers.md>), [cpu](<https://devfeed.tech/tags/cpu.md>), [google](<https://devfeed.tech/tags/google.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [image-processing](<https://devfeed.tech/tags/image-processing.md>), [jit](<https://devfeed.tech/tags/jit.md>), [jvm](<https://devfeed.tech/tags/jvm.md>), [mips](<https://devfeed.tech/tags/mips.md>), [native](<https://devfeed.tech/tags/native.md>), [r8](<https://devfeed.tech/tags/r8.md>)

## AI overview

The article traces Android code from Java/Kotlin source through class files and dex bytecode to execution, explaining Dalvik's interpreter/JIT and ART's shift toward profile-guided compilation. It describes ART's tradeoffs: compiling everything during installation increased install time and storage use, while interpreting and JIT-compiling hot code before idle-time AOT compilation aimed to reduce those costs. It then presents D8 as integrating desugaring into dex compilation to shorten builds, and experimental R8 as sharing D8's codebase while adding dex optimizations and some ProGuard-like shrinking, optimization, and obfuscation. The author reports project-specific build and APK improvements, including average savings of 2 seconds over 100 D8 builds and 13 seconds over 100 R8 builds, alongside about 1,122 methods removed; these are reported results, not general guarantees. The excerpt notes R8 supported only a subset of ProGuard features and was experimental at the time.

## Source excerpt

Imagine you have an important space mission ahead. You need a spacecraft that won't get you into much trouble on the way. You may opt in a regular YT-1300 freighter. It's popular and you know the basics of its operation. However, you've always dreamed of maneuvering like a pro. You are ready to practice a lot and learn various stuff. Millenium Falcon is what you actually want. But this upgraded spaceship will require that you master it like Han Solo! Lately, I've been inspired by the Google effort to improve compilers, such as the development of R8 or speeding up the Gradle builds. So I guess this is the right time to dig in and talk to you about those improvements. But first, let me guide you through the basics. When you reach the end of this article: You'll know about JVM and its relation to Android. You'll be able to read Bytecode. You'll get an idea of the Android Build System. You'll learn what AOT and JIT stand for and how they are connected to the new R8 compiler. And also a little bit about Star Wars :) So grab a large cup of good coffee, the lightsaber, cookies, and prepare for a read :) CPU & JVM In every device, there is a CPU. It's a tiny thing responsible for every single calculation in your app. In the beginning, the CPU could tackle only with basic math operations such as addition, subtraction, division, and multiplication. Over the years it has evolved into a complex mechanism that can be tailored for specific needs like Image Processing, Audio Decoding with a smart caching mechanism. The most known CPU is Snapdragon by Qualcomm. But there are others. Some of them use the same CPU architecture as Qualcomm, while some don't. And here I say 'Welcome to hell.' If you've ever developed C++/C, you know that your native code should be compiled to every supported CPU architecture: ARM, Arm64, x86, x64, MIPS. As an Android developer, you have to support CPU architectures for all the variety of devices. Basically, this means multiplying your .so files by the