An app is considered to have poor performance if it responds slowly, shows choppy animations, freezes, or consumes too much power. Fixing performance problems involves identifying areas in which your app makes inefficient use of resources such as the CPU, memory, graphics, network, or the device battery.
To find and fix these problems, use the profiling and benchmarking tools and techniques described in this topic. To learn techniques for measuring performance and examples of how to use these techniques to resolve specific problems, see Measuring performance.
Android Studio offers several profiling tools to help find and visualize potential problems:
- CPU profiler helps track down runtime performance issues.
- Memory profiler helps track memory allocations.
- Network profiler monitors network traffic usage.
- Energy profiler tracks energy usage, which can contribute to battery drain.
For more information about these tools, see the Android Studio Profilers page.
The Jetpack Benchmark libraries allow your application to measure various important operations:
- Macrobenchmark: Measure important performance use cases, including application startup and redrawing that is triggered by actions such as UI animations or scrolling.
- Microbenchmark: Measure CPU cost of specific functions.
To learn more about these libraries, see the Benchmark your app page.
Profileable applications
Profileable
is a manifest
configuration introduced in Android Q. It can specify whether the user
of the device can profile this application through tools such as Android Studio, Simpleperf, and
Perfetto.
Prior to profileable
, most developers could only profile debuggable apps on Android, which added
significant performance costs as a side effect. These performance costs could invalidate profiling
results, especially if they were related to timing. Table 1 summarizes the differences between
debuggable and profileable apps.
Feature | Debuggable | Profileable |
---|---|---|
Memory Profiler | Full |
Yes: No:
|
CPU Profiler | Full |
Yes:
No:
|
Network Profiler | Yes | No |
Energy Profiler | Yes | No |
Event Monitor | Yes | No |
Profileable
has been introduced so that developers can choose to allow their apps to expose
information to profiling tools, while incurring very little performance costs. A profileable APK
is essentially a release APK with a line of <profileable android:shell="true"/>
added within the <application>
section of the manifest file.
To build a profileable application, you need to first build a release application and then update its manifest file, which turns the release application into a profileable application.
Build a release app
To build a release application for profiling purposes, do the following:
-
Sign your application with the debug key by adding the following lines to your application's
build.gradle
file. If you already have a working release build variant, you can skip to the next step.buildTypes { release { signingConfig signingConfigs.debug } }
-
In Android Studio, select Build > Select Build Variant... and choose the release variant.
Change release to profileable
-
Convert your release application from above into a profileable application by opening the
AndroidManifest.xml
file and adding the following within<application>
. For more details, see Building your application for release.<profileable android:shell="true"/>
-
Depending on the SDK version, you may need to add the following lines to the application's
build.gradle
file.aaptOptions { additionalParameters =["--warn-manifest-validation"] }
Profile a profileable app
To profile a profileable app, do the following:
-
From the development emulator or device, start the app.
-
In Android Studio, launch the profiler by selecting View > Tool Windows > Profiler.
-
After the application has launched, click the
button in the profiler to see the dropdown menu. Select your device, then select the application's entry under Other profileable processes.
-
The profiler should attach to the application. Only the CPU and Memory Profilers are available, with limited capabilites for the Memory Profiler.