#Android

Improve Android App Performance With Baseline Profiles

 

baseline-profile-header-image

 

Introduction

In today's rapidly evolving mobile ecosystem, users expect apps to launch instantly and operate seamlessly. Optimizing performance is crucial, particularly in terms of startup speed and runtime efficiency.

At Vodafone, our primary focus is the customer experience. The Android Chapter continuously adapts to new technologies to enhance user experience in our applications.

In this blog post, we'll explore Baseline Profiles and their role in improving app performance, including boosting startup speed by up to 20%. While our primary focus is on startup optimization, Baseline Profiles also play a key role in reducing jank frames.

Code Execution History in Android

When an app is launched for the first time after installation or an update, its code initially runs in an interpreted mode until it is JITed (Just-In-Time compiled). In an APK, Java and Kotlin code are compiled into DEX bytecode rather than fully compiled into machine code (a change introduced in Android 6) to reduce storage and loading costs. 

Frequently used classes and methods, including those essential for app startup, are recorded in a profile file. Once the device enters idle mode, ART (Android Runtime) compiles the app using these profiles, leading to faster subsequent launches.

Starting with Android 9 (API level 28), Google Play introduced Cloud Profiles. When an app runs on a device, ART generates profiles that are uploaded by the Play Store app and aggregated in the cloud. Once a sufficient number of profiles are collected, the Play Store uses this aggregated data to optimize subsequent installs of the app.

The Problem

Although Cloud Profiles offer significant benefits, they aren't always immediately available when an app is installed. The process of collecting and aggregating profiles typically takes several days, posing a challenge for apps that receive frequent weekly updates. As a result, many users may install an update before the Cloud Profile is ready and cannot take advantage of it.

  baseline-problem.png

Source: Android Developers Youtube

Baseline Profiles to the Rescue

Baseline Profiles are a recently introduced feature that allows developers to provide performance profiles for Android 7 (API level 24) and above. These profiles, generated by the Android Gradle plugin, use a human-readable format and can be supplied by both apps and libraries to enhance performance.

baseline-profile-cloud.png

Source: Android Developers 

With Baseline Profiles, we can ship our applications to the Play Store with the profiles embedded in the APK/Bundle, allowing users to experience improvements immediately. 

Moreover, these profiles can be created without requiring any refactoring of the existing codebase.

Baseline Profile and Jetpack Compose

In most cases, Baseline Profiles boosts your app's performance. However, the impact is particularly significant when your project depends on multiple third-party libraries, such as popular Jetpack libraries. In these scenarios, your app benefits from even greater optimization and performance improvements.

For example, Jetpack Compose is provided as a standalone library rather than being integrated into the Android platform. This approach allows the Compose team to release frequent updates while maintaining compatibility across various Android versions. 

However, this flexibility can lead to slower startup times and performance issues when accessing library features for the first few cold launches of the app.

To address this, Google recommends using Baseline Profiles to enhance Jetpack Compose performance.

The Implementation

Before we started the implementation, we first identified the Critical User Journeys (CUJs) where the profiler would capture.

We focus on the critical user journey in the MyCU app (our youth branded application), from app startup to the dashboard screen flow, ensuring that our customers receive the the best experience.

To optimize different parts of the app, we split these journeys into three Baseline Profile generators:

  • Onboarding flow
  • Dashboard scrolling
  • Coupon Creation flow

Results

After integrating Baseline Profiles into our application, we observed substantial performance improvements across various key metrics.

  • Startup Time:  App cold start time was reduced by over 20%, decreasing from 2.42% to 1.98%, as reported by Android Vitals and Firebase Performance Monitoring.
  • Dashboard Screen: We observed a 38.7% reduction in jank frames and a 9.2% decrease in frame duration, leading to a smoother UI experience.
  • Coupons Screen: Jank frames decreased by 33.8%, with frame duration improving by up to 10.5%, enhancing responsiveness during interactions.

To verify the reduction in app startup time, jank frames and frame duration, we conducted Macrobenchmark tests, ensuring a comprehensive and reliable performance assessment.

mycuapp.jpg

Summary

Baseline Profiles have proven to be an effective optimization strategy, enabling us to enhance app performance without modifying the existing codebase. By embedding these profiles directly in the APK, users experience faster startup times and improved runtime performance immediately after installation. This approach is particularly beneficial for apps that receive frequent updates, ensuring that optimizations are available even before Cloud Profiles become active.

Next steps

To further improve our app’s performance, we plan to:

  • Integrate Baseline Profile generation into our CI/CD pipeline to ensure optimizations are consistently applied with every release.
  • Expand profiling coverage to additional Critical User Journeys (CUJs) to enhance the overall user experience.

By continuously refining our approach, we aim to provide a seamless, high-performance experience for all users.

References

https://developer.android.com/topic/performance/benchmarking/benchmarking-overview

https://developer.android.com/develop/ui/compose/performance/baseline-profiles

https://developer.android.com/topic/performance/baselineprofiles/overview

https://medium.com/androiddevelopers/improving-performance-with-baseline-profiles-fdd0db0d8cc6

https://github.com/android/performance-samples

 

 

 

Loading...