Author/Android developer relations Engineer Florina Muntenescu

The importance of startup time

The correlation between application performance and user engagement is evident in many applications. Users expect applications to be responsive and fast to load, and startup time is one of the key metrics for application performance and quality.

Some of our partners have invested significant time and resources to optimize application launch. For example, you can read about Facebook’s optimization process.

In this article we’ll discuss benchmark profiles and the ways they can improve application and development library performance, including how they can reduce startup times by up to 40%. Although this article focuses on application startup, the baseline profile can also greatly improve the lag situation.

review

Android 9 (API level 28) introduces ART optimization profiles in Play Cloud to shorten app launch times. When cloud profiles were available, we saw cold startup of applications at least 15% faster on average across devices.

How configuration files work

When an application is first started after installation or update, its code runs in interpreted mode until JIT. Since Android 6, Java and Kotlin code is compiled to dex bytecode in APK rather than fully compiled to machine code because of the overhead of storing and loading a fully compiled application. Classes and methods that are frequently used in the application and used to start the application are written to the configuration file. Once the device is in idle mode, ART compiles the application based on these profiles to speed up subsequent application launches.

Starting with Android 9 (API level 28), Google Play will also provide cloud profiles. When the app is running on the device, the configuration files generated by ART are uploaded by the Play Store app and aggregated in the cloud. Once you have uploaded enough profiles for your app, the Play app will use the aggregated profiles for subsequent installations.

Existing problems

While cloud profiles are helpful when they are available, they are not always available after an application is installed. Collecting and aggregating profiles usually takes a few days, and many applications update weekly, which is the problem. And many users install updates before cloud profiles become available. The Google Android team started looking for other ways to improve profile latency.

The solution

Benchmark profiles are a new mechanism for providing profiles and are available on Android 7 (API level 24) and later. The base profile is an ART profile generated by the Android Gradle plug-in in a human-readable profile format provided by the application and library. The following is an example:

HSPLandroidx/compose/runtime/ComposerImpl; ->updateValue(Ljava/lang/Object;) V HSPLandroidx/compose/runtime/ComposerImpl; ->updatedNodeCount(I)I HLandroidx/compose/runtime/ComposerImpl; ->validateNodeExpected()V PLandroidx/compose/runtime/CompositionImpl; ->applyChanges()V HLandroidx/compose/runtime/ComposerKt; ->findLocation(Ljava/util/List; I)ICopy the code

△ Example of Compose library

Binary files are stored in the APK resource directory specific location (assets/dexopt/baseline. Initial).

The benchmark profile is created at build time, sent to Play as part of the APK, and then sent from Play to the user when the application is downloaded. The benchmark profile fills a gap in the ART cloud profile pipeline when the cloud profile is not yet available, and is automatically merged with the cloud profile when it is available.

This diagram shows the baseline profile workflow from creation to delivery to the end user.

One of the biggest advantages of benchmark profiles is that they can be developed and evaluated locally, so developers can see real end-user performance improvements. They also support lower Versions of Android (7 and later), while cloud profiles are only available in Android 9 and above.

impact

App developer

In early 2021, Google Maps changed its release cycle from two weeks to one. More frequent updates mean more frequent abandonment of native precompilation and more users experiencing slow starts without Play Cloud profiles. By using the base profile, Google Maps reduced the average startup time by 30% and increased search speed by 2.4%, which is a huge performance improvement for such a mature application.

Library developers

The code in the library is similar to the code in the application and is not fully compiled by default, which can be problematic if it plays a major role in the startup critical path.

Jetpack Compose is an interface library that is not part of the Android system image, so unlike most Android View toolkit code, it is not fully compiled at installation time. This causes performance problems, especially during the first few cold starts of the application.

To address this issue, Compose uses a configuration file installer. The application comes with baseline profile rules that shorten the Compose application’s startup time and reduce latency.

The Google Play store search results page has been rewritten using Compose. After integrating Compose’s baseline profile rules, the time to render initial search results pages, including images, was reduced by approximately 40%.

The Android team also added the benchmark profile to the relevant AndroidX library. This will benefit all Android apps that use these libraries. ConstraintLayout found that the accompanying configuration file rules reduced the animation frame time by more than 1 millisecond.

How do I use a baseline profile

Create a custom baseline profile

All application and library developers can benefit from adding baseline profiles. Ideally, developers create profiles for the most critical user journeys to ensure that these journeys have consistently fast performance regardless of whether cloud profiles are available. You can check out the detailed guide on how to set up the baseline profile for application and library developers.

Update dependencies

If you are not ready to generate a baseline profile for your application, you can still benefit from updating dependencies. If you build your application using the Android Gradle plug-in 7.1.0-Alpha05 or higher, you will get the baseline profiles included in APK that are already provided by libraries such as Jetpack. Google Play uses these profiles to compile the app at install time. You can use these configuration files as a complementary part of building your application.

Measure improvement

Don’t forget to measure application improvement. You can follow the steps to learn how to measure startup locally using the generated configuration file.

Welcome to share your feedback.

If you have any other problems or content suggestions, please click here to submit feedback to us, or share your favorite content and found problems. Your feedback is very important to us, thank you for your support!