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. You can use your knowledge from Jetpack Compose to configure and develop your app to improve performance with Compose for Wear OS, as many of the techniques are similar. However, it's important to understand how to test your app's performance on Wear OS.
To better understand performance concepts, watch Performance best practices and Create beautiful, power efficient apps for Wear OS on YouTube.
Techniques to improve performance
To accurately understand your app’s performance, try running your app in release mode. Debug mode is useful for spotting lots of problems, but it imposes a significant performance cost, and can make it hard to spot other code issues that might be hurting performance. In addition, debug mode does not use baseline profiles, which can further deteriorate performance. You should also use the R8 compiler to shrink and optimize your app. For more information on removing unused resources, see Shrink your resources.
Familiarize yourself with Android Studio tools including Live Edit, Composable Preview, and Wear OS emulator. This can reduce the amount of time spent debugging your app on a watch, which can improve your productivity. Android Studio ships with a watch AVD. Test with Compose Previews and Live Edit until your app is largely working as expected, then test on a device for an accurate reflection of your app’s performance.
Use the JankStats library to track and analyze performance problems in your applications. For an example, see the JankStats sample on GitHub.
Use a baseline profile
Use a baseline profile to improve your app's performance by defining classes and methods needed on critical user journeys. For an in depth guide on this topic, see Baseline profiles. Each Compose for Wear OS 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 and are compiled ahead of time on device. This can reduce start-up times, cut down janky frames, and otherwise improve performance.
If you choose to define your own profile for an app, verify that it does improve performance by writing Macrobenchmark tests. For an example, see Performance samples on GitHub.
Baseline profile commands
There are some useful commands you can use to help working with baseline profiles. First, determine the status of your profile by running the following:
adb shell dumpsys package dexopt | grep -A 1 $PACKAGE_NAME
If the status is not status=speed-profile
, the rules have not yet been applied
to optimize the app.
Compose for Wear OS profile 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.
Recommended for you
- Note: link text is displayed when JavaScript is off
- Overview of measuring app performance