Improving Performance with Baseline Profiles

Ben Weiss
Android Developers
Published in
3 min readAug 23, 2022

A quick rundown of Baseline Profiles

Illustration by Claudia Sanchez

In this MAD Skills article on improving performance with Baseline Profiles you’ll learn what Baseline Profiles are and how they can be used to improve app startup and speed up runtime.

Baseline Profiles help your app to start and run faster by optimizing critical code paths ahead of time. This allows for a smoother user experience.

We have seen significant app launch and runtime improvements thanks to using Baseline Profiles. You can read on how Google Maps improved their app launch time by up to 40 % after introducing Baseline Profiles.

You can watch the accompanying video to this article here.

Improving Performance with Baseline Profiles

Baseline Profiles in a nutshell

Baseline Profiles are a list of classes and methods that are ahead of time compiled and installed with your app. This means that your code does not need to be interpreted using the just-in-time (JIT) compiler when the app is used. This translates into startup time improvements, reduced jank, and overall improved runtime performance for end users.

Baseline Profiles can be generated for applications and bundled with the app that’s being shipped to users. But also libraries can create their own Baseline Profile and ship it with their AAR. The Baseline Profiles from libraries will be merged into an application’s Baseline Profile and then compiled into a single file, which is shipped with the app itself.

To speed up the development process, Baseline Profiles are not installed for debug builds but only for release builds. So, to see the performance gains of your profile, always verify it against a release build.

Always verify performance gains in a release build.

Jetpack Compose is a popular example for a library that provides a Baseline Profile. By offering library consumers this profile, Jetpack Compose can minimize the impact of being an unbundled UI toolkit for release builds of an app.

Generating a Baseline Profile

The Macrobenchmark library comes with a rule to generate Baseline Profiles for you. By using UIAutomator you can drive the profile generator through an app’s critical user journeys. The API calls made in the app will be captured and integrated into the Baseline Profile which the Macrobenchmark library creates.

The minimum viable setup for a baseline profile generator looks like this.
Below code will generate a baseline profile for you and you can implement clickThroughUserJourney() to guide the generator to more complex scenarios.

@ExperimentalBaselineProfilesApi
@RunWith(AndroidJUnit4::class)
class BaselineProfileGenerator {
@get:Rule
val baselineProfileRule = BaselineProfileRule()

@Test
fun startup() = baselineProfileRule.collectBaselineProfile(
packageName = "com.example.app"
) {
pressHome()
startActivityAndWait()
clickThroughUserJourney()
}
}

You can see a how a trivial Baseline Profile generator is set up in our sample app on GitHub. And the Now in Android sample app has a more complex Baseline Profile setup.

To learn more about the Macrobenchmark library and how to set up a benchmark, read the previous article in this series, or watch the video.

Inspecting Performance

The codelab to create a Baseline Profile guides you through the latest best practices to get started and leaves you with a first Baseline Profile.

While you wait for the next article

The next article is all about monitoring app performance.

Go and check out our improved developer documentation, which we have been updating with MAD guidance.

To get more detailed code, check out the samples on GitHub or take the Macrobenchmarking Codelab or Baseline Profiles Codelab for hands-on guidance through the topics.

Make sure to ask your questions in the video comments or on Twitter, using #MADPerfQA to get answers directly from the Engineers working on Android Performance in our Q&A session on Sept 1st

And check out the full MAD Skills series on performance debugging to get an edge on how you can inspect what’s going on in your code.

Performance Debugging

--

--