𝗣𝗿𝗼𝗳𝗶𝗹𝗲-𝗚𝘂𝗶𝗱𝗲𝗱 𝗢𝗽𝘁𝗶𝗺𝗶𝘇𝗮𝘁𝗶𝗼𝗻 𝗳𝗼𝗿 𝗔𝗻𝗱𝗿𝗼𝗶𝗱 𝗔𝗽𝗽 𝗦𝘁𝗮𝗿𝘁𝘂𝗽

We cut our Android cold start from 1.2s to 380ms.

Most apps run on the slowest compilation mode during the first launch. Android uses "interpret-only" mode when a user first installs your app. This makes your startup slow. The system only optimizes code during idle time later.

You can fix this using a three-step pipeline.

  1. Generate Baseline Profiles Baseline Profiles tell the system which classes to compile at install time. Use Macrobenchmark to create these in your CI pipeline. Our profiles covered 12% of methods but handled 94% of the startup time.

  2. Enable DEX Layout Reordering This is a single line in your Gradle properties. It tells R8 to group startup classes together in your DEX file. This reduces page faults by 30% to 50%. When classes stay together, the system loads less useless data from the disk.

  3. Use Cloud Profiles Google Play collects profiles from users and sends them to new installs. This compounds your speed gains.

The results of our testing:

Important tips for your workflow:

Stack these layers to build faster apps.

Source: https://dev.to/software_mvp-factory/profile-guided-optimization-for-android-app-startup-2i7a