𝗣𝗿𝗼𝗳𝗶𝗹𝗲-𝗚𝘂𝗶𝗱𝗲𝗱 𝗢𝗽𝘁𝗶𝗺𝗶𝘇𝗮𝘁𝗶𝗼𝗻 𝗳𝗼𝗿 𝗔𝗻𝗱𝗿𝗼𝗶𝗱 𝗔𝗽𝗽 𝗦𝘁𝗮𝗿𝘁𝘂𝗽
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.
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.
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.
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:
- No profile: 1,204ms cold start
- Baseline Profile only: 620ms cold start
- Baseline + DEX reorder: 445ms cold start
- Baseline + DEX reorder + Cloud: 380ms cold start
Important tips for your workflow:
- Generate profiles in CI for every release. Stale profiles cause performance loss.
- Regenerate profiles after R8 runs. R8 changes your code structure.
- Use "Partial" compilation mode in Macrobenchmark. "Full" mode gives fake results that do not reflect real user experiences.
- Test on different Android versions. Performance gains vary between older and newer API levels.
Stack these layers to build faster apps.
Source: https://dev.to/software_mvp-factory/profile-guided-optimization-for-android-app-startup-2i7a