Baseline Profiles

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

Baseline Profiles improve code execution speed by around 30% from the first launch by avoiding interpretation and just-in-time (JIT) compilation steps for included code paths. By shipping a Baseline Profile in an app or library, Android Runtime (ART) can optimize included code paths through Ahead of Time (AOT) compilation, providing performance enhancements for every new user and on every app update. This profile guided optimization (PGO) lets apps optimize startup, reduce interaction jank, and improve overall runtime performance for end users from the first launch.

These speed improvements directly result in improved business metrics such as user retention, transactions, and ratings. You can read more about how performance impacts business metrics in stories from Josh, Lyft, TikTok, and Zomato.

Benefits of Baseline Profiles

With a Baseline Profile, all user interactions (such as app startup, navigating between screens, or scrolling through content) are smoother from the first time they run. Increasing the speed and responsiveness of an app leads to more daily active users and a higher average return visit rate.

Baseline Profiles help guide optimization beyond app startup by providing common user interactions that improve app runtime from the first launch. 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. By shipping releases with a Baseline Profile, app optimizations become available much faster than by relying on Cloud Profiles alone.

When not using a Baseline Profile, all app code is JIT compiled in memory after being interpreted, or into an odex file in the background when the device is idle. Users have a less optimal experience for the first time they run an app after installing or updating it, until the new paths have been optimized. This performance boost has been measured at around 30% for many apps.

Get started

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

The dependency chain provides stable and developmental release versions. To generate and install a Baseline Profile, you need to use at least the minimally supported versions of the Android Gradle Plugin, Macrobenchmark library, and the Profile Installer. These dependencies are required at different times and work together as a toolchain to enable an optimal Baseline Profile.

  • Android Gradle Plugin: com.android.tools.build:7.3.0
  • Macrobenchmark: androidx.benchmark:benchmark-macro-junit4:1.1.1
  • Profile Installer: androidx.profileinstaller:profileinstaller:1.2.0

Profile generation example

Here is an example class to create a Baseline Profile for app startup, as well as several navigation and scroll events using the recommended Macrobenchmark library.

@OptIn(ExperimentalBaselineProfilesApi::class)
class TrivialBaselineProfileBenchmark {
    @get:Rule
    val baselineProfileRule = BaselineProfileRule()

    @Test
    fun appStartupAndUserJourneys() {
        baselineProfileRule.collectBaselineProfile(packageName = TARGET_PACKAGE) {
            startActivityAndWait()
            with(device) {
                findObject(By.text("RECYCLERVIEW")).clickAndWait(Until.newWindow(), 500L)
                with(findObject(By.res(TARGET_PACKAGE, "recycler"))) {
                    fling(Direction.DOWN)
                    waitForIdle()
                    fling(Direction.UP)
                    pressBack()
                }

                findObject(By.text("COMPOSE LAZYLIST")).clickAndWait(Until.newWindow(), 500L)
                with(findObject(By.res("myLazyColumn"))) {
                    fling(Direction.DOWN)
                    waitForIdle()
                    fling(Direction.UP)
                    pressBack()
                }
            }
        }
    }
}

You can see this code in full context and more detail as part of our performance samples on GitHub.

What to include

When using Baseline Profiles in an app, you can include app startup code and common user interactions, like navigation between screens or scrolling. You can also gather entire flows such as registration, login, or payment.

Libraries can provide their own Baseline Profile and ship 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 common user interactions where rendering time or latency are important.

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

  2. Google Play processes the profile and ships it directly to users along with the APK. During installation, ART performs 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 over time.

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

Cloud Profiles

Cloud Profiles offer an additional form of PGO, aggregated by Google Play Store and distributed for install time compilation, together with Baseline Profiles. While Cloud Profiles are driven by real world user interactions with the app, they take several days to weeks after an update to become distributed, limiting their availability. When only relying on a Cloud Profile, new and updating users experience apps in less than optimal performance until the profile is ready and distributed. Also, Cloud Profiles only support Android devices running Android 9 (API level 29) or higher and currently only scale well for apps that have a sufficiently large user base.

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 or 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 com.android.tools.build:gradle:7.3.0 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 com.android.tools.build:gradle:7.3.0 and higher (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 currently support compiling Baseline Profiles into output APKs.

  • Play Store currently takes 10-14 hours after aab upload to make Baseline Profiles available at installation. Users downloading the app during this time don't see the benefits until background dexopt runs (likely overnight). This is being actively improved.

  • Non-Play Store app distribution channels may not support using Baseline Profiles at installation. Users of the app through these channels don't see the benefits until background dexopt runs (likely overnight).