Baseline Profiles

Stay organized with collections Save and categorize content based on your preferences.

Baseline Profiles are a list of classes and methods included in an APK used by Android Runtime (ART) during installation to pre-compile critical paths to machine code. This is a form of profile guided optimization (PGO) that lets apps optimize startup, reduce jank, and improve performance for end users.

Many apps have seen performance improvements using Baseline Profiles including Josh, Zomato, and OkCredit.

To get started with optimizing performance in your existing app, see Creating a Baseline Profile.

Reasons for using Baseline Profiles

Startup time is a critical component to improve user engagement with your application. Increasing the speed and responsiveness of an app leads to more daily active users and a higher average return visit rate.

Cloud Profiles also optimize these same interactions, but are only available to users a day or more after an update is released and don't support Android 7 (API 24) up to Android 8 (API 26).

Baseline Profiles help guide optimization beyond app startup by providing critical user journeys that improve app runtime from the first launch, by moving from JIT compilation to AOT. Guided AOT compilation doesn't rely on user devices and can be done once per release on a development machine instead of a mobile device.

Libraries can also participate by providing their own Baseline Profile and shipping it as part of a release to improve app performance. For example, take a look at Using a Baseline Profile with Compose.

How Baseline Profiles work

While developing your app or library, consider defining Baseline Profiles to cover specific hot paths during critical user journeys where rendering time or latency are important, such as startup, transitions, or scrolling.

  1. Profile rules are generated for your app in human readable form and compiled into a binary form in the APK, which you can find in assets/dexopt/ You can then upload the APK to Google Play as you normally would.

  2. Google Play processes the profile and then ships directly to users along with the APK. During installation, ART performs Ahead-of-time (AOT) compilation of methods in the profile, resulting in those methods executing faster. If the profile contains methods used in app launch or during frame rendering, the user may experience faster launch times and reduced jank.

  3. This flow cooperates with Cloud Profiles aggregation to fine-tune performance based on actual usage of the app.

Figure 1. This diagram displays the baseline profile workflow from upload through end-user delivery, and how that workflow relates to cloud profiles.

Compilation behavior across Android versions

Android Platform versions have used different app compilation approaches, each with a corresponding performance tradeoff. Baseline profiles improve upon the previous compilation methods by providing a profile for all installs.

Android version Compilation method Optimization approach
Android 5 (API level 21) up to Android 6 (API level 23) Full AOT The entire app is optimized during install, resulting in long wait times to use the app, increased RAM and disk space usage, and longer times to load code from disk, potentially increasing cold startup times.
Android 7 (API level 24) up to Android 8.1 (API level 27) Partial AOT (Baseline Profile) Baseline Profiles are installed by androidx.profileinstaller on the first run, when the app module defines this dependency. ART may improve this further by adding additional profile rules during the app's use and compiling them when the device is idle. This optimizes for disk space and time to load code from the disk, thereby reducing wait time for the app.
Android 9 (API level 28) and higher Partial AOT (Baseline + Cloud Profile) Play uses Baseline Profiles during app installs to optimize the APK and Cloud profiles (if available). After installation, ART profiles are uploaded to Play and aggregated, then provided as Cloud Profiles to other users when they install/update the app.

Known Issues

Currently, using Baseline Profiles has several known issues:

  • Baseline profiles are not packaged correctly when building the APK from an app bundle. To resolve this issue, apply and higher (issue).

  • Baseline profiles are only correctly packaged for the primary classes.dex file. This affects apps with more than one .dex file. To resolve this issue, apply and higher (issue).

  • Macrobenchmark is incompatible with Baseline Profiles on Android 12L (API 32) (issue) and Android 13 (API 33) (issue).

  • Resetting ART profile caches is not allowed on user (non-rooted) builds. To work around this, androidx.benchmark:benchmark-macro-junit4:1.1.0 includes a fix that reinstalls the app during the benchmark (issue).

  • Android Studio Profilers don't install Baseline Profiles when profiling the app (issue).

  • Non Gradle build systems (Bazel, Buck, etc.) don't support compiling Baseline Profiles into output APKs.