Optimize Android runtime

Android Lollipop includes a new virtual machine called ART (Android Runtime.) ART uses AOT (ahead-of-time) compilation into native code, which performs better than JIT (just-in-time) compilation into bytecode. You can configure ART to perform this optimization in different ways.

Android Lollipop includes the dex2oat tool for optimizing applications on deployment.

For a complete overview, see the Android documentation.

Pre-optimize the system image

The Android build system includes a build parameter that allows you to pre-optimize all parts of the system.img. This system image optimization results in lower boot times both at deployment and normal boots.

Add the following entry to the BoardConfig.mk to enable this feature:

WITH_DEXPREOPT := true

The resulting image includes the pre-optimized files for each application. Pre-optimized files take more space in the system image, so this option produces a larger system image size.

Optimize the system image at first boot

You can optimize the system runtime at first boot with a specific compiler filter used by the dex2oat tool. To do so, add the following entry to the BoardConfig.mk:

ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.image-dex2oat-filter=<dex2oat-compiler-filter>

Replace the parameter value <dex2oat-compiler-filter> with one of the following:

Parameter value Description
everything Compiles almost everything, excluding class initializers and some rare methods that are too large to be represented by the compiler’s internal representation.
speed Compiles most methods and maximizes runtime performance, which is the default option.
balanced Attempts to get the best performance return on compilation investment.
space Compiles a limited number of methods, prioritizing storage space.
interpret-only Skips all compilation and relies on the interpreter to run code.
verify-none Special option that skips verification and compilation; should be used only for trusted system code.

During compilation, the build script adds this setting to the build.prop file in the system partition. On the first deployment/boot, the dex2oat optimizes the system applications with the set compiler filter. The system then starts up faster on subsequent boots due to the optimized code.

Note Filter dalvik.vm.image-dex2oat-filter only applies if pre-optimization WITH_DEXPREOPT is disabled.

Optimize new applications

The ART VM also includes parameters that increase the performance of new applications installed in a running Android system. You must add the following compiler filter to the BoardConfig.mk.

ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.dex2oat-filter=<dex2oat-compiler-filter>

Replace <dex2oat-compiler-filter> with one of the values described in the parameter value table in Optimize the system image at first boot.

During compilation, the build script adds this setting to the build.prop file in the system partition. The dex2oat tool uses this filter to optimize any application during installation on the running system.

Default Android image optimization

The following table lists default configuration of the eng and user images:

Image Pre-optimization Optimization at first boot Optimization of new applications
eng WITH_DEXPREOPT := true dalvik.vm.image-dex2oat-filter=verify-none dalvik.vm.dex2oat-filter=speed
user WITH_DEXPREOPT := true dalvik.vm.image-dex2oat-filter=speed dalvik.vm.dex2oat-filter=speed