Jetpack Compose performance on Wear OS

Performance on Wear OS is an essential app consideration, as many Wear OS devices have limited CPU and GPU resources compared to larger mobile devices. With the introduction of richer animations and dynamic effects in Material 3 Expressive, you should validate and improve the performance of your app's key workflows.

Use the Jetpack Compose Performance guide to configure and develop your app for optimal performance using Jetpack Compose. This document highlights some of the techniques described there.

Also, create and follow performance measurement strategies to validate that the techniques in this document are working as expected for your app.

Essential performance improvement techniques

Start with the most impactful performance tool types: baseline profiles (including startup profiles) and the R8 code optimizer.

Before getting started, we recommend that you update your Compose dependency to at least version 1.8, which introduced several significant new features and improved the overall stability of the library. See the instructions in Declaring dependencies to learn how to update, and to learn more, check out our blog about the 1.8 release and the What's New in Compose I/O talk.

Baseline profiles

Use baseline profiles to improve your app's performance. Group together the classes and methods that represent your app's key workflows, which the system can pre-compile using a baseline profile. This can reduce start-up times, cut down on janky frames, and offer additional performance improvements.

Each Jetpack Compose library ships with its own profile rules. When your app depends on a library, the library profile rules are automatically merged and distributed with your app's APK for precompilation.

Verify your baseline profiles using the following techniques:

  • Use macrobenchmark tests.
  • Leverage specific ADB commands to validate the state of your app's profile configuration.

Steps for both of these techniques are explained in the performance measurement and validation guide.

Startup Profiles

As a subset of baseline profiles, Startup Profiles further optimize the classes and methods they contain to decrease app startup latency.

Adding a startup profile will increase the APK size of your app, so before adding one to your production release, be sure to assess the tradeoff between APK size and startup latency.

Once you are generally comfortable with your baseline profiles setup, read Create a Startup Profile to get started.

R8

Use the R8 compiler to shrink and optimize apps. R8 removes unused code and resources, rewrites code to optimize runtime performance, and more.

In the guides on how to improve performance Overview, review the considerations for R8, including key steps for removing unused resources.

Performance Measurement and Validation

To learn about general performance measurement strategies on Android, see Overview of measuring app performance. This section contains a few of the techniques discussed in that documentation.

Choose a build variant for measurements

While debug mode is useful for spotting many problems, it imposes a significant performance cost, doesn't use baseline profiles, and can make it hard to spot code issues that might be hurting performance.

To accurately understand your app's performance, run your app in release mode.

You should only draw final conclusions on performance using tests performed with apps running with release build options, and on real devices.

However, when benchmark testing, use the benchmark build variant, which has some key differences with release debugging. See the Macrobenchmark setup guide for details.

Validate your app's baseline profiles

Start by inspecting the status of your profile:

adb shell dumpsys package dexopt | grep -A 1 $PACKAGE_NAME

If the status is not status=speed-profile, profile rules have not yet been applied to optimize the app.

Rules are applied using a background job which runs when the device is charged and idle. You can manually trigger this by running the following command after the app has been launched and enough time has passed to allow the profile-installer to bootstrap the profile in the background. This typically takes around 40 seconds.

adb shell cmd package bg-dexopt-job

You can then re-run the previous command to check that the status is now speed-profile.

For situations when the optimisation is performed at install, see Sideload the baseline profile.

UI Automator API

Use the UI Automator API to benchmark discrete pieces of UI when inspecting user journeys for potential optimizations.

It works by automating UI interactions programmatically.

Macrobenchmark tests

Macrobenchmarks test larger use cases of your app, especially app startup and complex UI manipulations. See the implementation guide to get started.

For an example of using macrobenchmarks to validate the performance of Baseline profiles, see the performance samples on GitHub.

JankStats Library

Use the JankStats library to track and analyze performance problems in applications.

For an example, see the JankStats sample on GitHub.

System Trace

With the new animation types introduced by Material 3 Expressive, you can use the System Trace feature in Android Studio to inspect and diagnose latency in potentially problematic user journeys. Given this information, you can then verify the content of your baseline profiles, and inspect your code logic to look for places with potential inefficiencies.

Additional tools

Besides performance improvement tools, there are other tools developers can use to improve their productivity and workflow.

Android Studio Productivity Tools

Android Studio provides several tools which can reduce the amount of time you spend looking for ways to improve performance.

For example, using tools like Live Edit and Composable Previews, you can identify janky UI, along with the associated areas in your app's code, for performance improvements.

Run all final performance tests on a suite of physical Wear OS devices that accurately represents your target user base.

This is especially important when migrating to Material 3 Expressive, which introduces features like flex fonts and shape morphing to your app.

If you are migrating from views, check out out migration guide and our best practices for Jetpack Compose performance to verify that your app's UIs are performant when using Jetpack Compose.

Other resources

To stay up to date with the latest in android performance, check out the Latest news and videos in the App performance guide.