Author / Android Developer Relations Engineer Florina Muntenescu
of boot time
The correlation between application performance and user engagement is seen in many applications. Users expect applications to be responsive and fast to load, and startup time is one of the main indicators to measure application performance and quality.
Some of our partners have invested significant time and resources in optimizing app launches. For example, you can read Understanding Facebook's Optimization Journey .
In this article we'll discuss the benchmark profile and how it improves application and library performance, including how they reduce startup time by up to 40% for . While this article focuses on application startup, benchmark profiles can also greatly improve stuttering.
Review
Android 9 (API level 28) introduced the ART optimization profile in Play Cloud to improve app startup time. When cloud profiles are available, we see cold starts of apps averaging at least 15% faster across devices.
How the profile works
When an app is first launched after an installation or update, its code runs in interpreted mode until it is JIT . Because of the overhead required to store and load a fully compiled app, starting with Android 6, Java and Kotlin code is compiled to dex bytecode in the APK, rather than fully compiled to machine code. The classes and methods that are frequently used in the application and used for application startup will be written to the configuration file. Once the device enters idle mode, the ART compiles applications based on these profiles to speed up subsequent application launches.
Starting with Android 9 (API level 28), Google Play also provides cloud profiles. When the app runs on the device, the ART-generated configuration file is uploaded by the Play Store app and aggregated in the cloud. Once enough profiles have been uploaded for the app, the Play app will use the aggregated profile for subsequent installations.
Problems with
While cloud profiles are helpful when they are available, they are not always available after the app is installed. Gathering and aggregating profiles often takes days, and many apps are updated weekly, which is the problem. And many users install updates before cloud profiles are available. The Google Android team started looking for other ways to improve profile latency.
Solution
Baseline Profile is a new mechanism for providing profiles, available on Android 7 (API level 24) and higher. Baseline configuration files are ART configuration files generated by the Android Gradle plugin , in a human-readable configuration file format that can be provided by apps and libraries. Examples are as follows:
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)I
△ Example of Compose library
Binaries are stored in a specific location in the APK assets directory (assets/dexopt/baseline.prof).
Baseline profiles are created at build time, sent to Play as part of the APK, and then sent from Play to the user when the app is downloaded. Baseline profiles fill gaps in the ART cloud profile pipeline when cloud profiles are not yet available, and are automatically merged with cloud profiles when they are available.
△ This diagram shows the baseline profile workflow from creation to delivery to end users.
One of the biggest advantages of the benchmark profile is that can be developed and evaluated , so developers can see real end-user performance improvements. They also support lower Android versions (7 and above), while cloud profiles are only available in Android 9 and above.
affects
Application Developer
In early 2021, the release cycle for Google Maps will be changed from two weeks to one week. More frequent updates means dropping local precompiles more often, and more users experiencing slow startups without a Play Cloud profile. By using the baseline profile, Google Maps reduced average startup time by 30%, with a corresponding increase in search speed of 2.4% , a huge performance improvement for such a mature application.
Library Developer
The code in the library is similar to the code in the app, neither is fully compiled by default, and if it plays an important role in the critical path of startup, there may be problems.
Jetpack Compose is an interface library that is not part of the Android system image, so unlike most Android view kit code, it is not fully compiled at install time. This caused performance issues, especially during the first few cold starts of the app.
To address this, Compose uses the profile installer . The program comes with baseline profile rules that reduce Compose app startup time and stutter.
The Google Play Store search results page has been rewritten using Compose. After integrating Compose's baseline profile rules, reduced the time to render the initial search results page (including images) by about 40%.
The Android team also added baseline profiles to the related AndroidX library. This benefits all Android apps that use these libraries. ConstraintLayout found that the profile rules that come with reduce animation frame times by over 1ms.
How uses the baseline profile
Create 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 always-fast performance regardless of the availability of cloud profiles. You can check out detailed guide to learn how to set up a baseline profile for app and library developers.
update dependencies
If you're not ready to generate a baseline profile for your app, you can still benefit from updating your dependencies. If you build your app with Android Gradle Plugin 7.1.0-alpha05 or higher, you will get baseline profiles included in the APK already provided by libraries (eg Jetpack ). Google Play uses these configuration files to compile apps at install time. You can use these configuration files as a supplemental part of to your build application.
Measuring Improvements
Don't forget to measure app improvements. You can the steps to learn how to locally measure startup using the generated configuration file.
Welcome to share your experience feedback .
If you have other problems or content suggestions, you are welcome to here to submit feedback to us, or share your favorite content and problems found. Your feedback is very important to us, thank you for your support!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。