Posted by Yi Yang (Software program Engineer)It’s vital to remain on prime of your app efficiency to ensure your customers can simply use your app. When an app experiences points similar to animation jank, frozen frames, and excessive reminiscence utilization, it negatively impacts the consumer expertise which might result in decrease rankings or app deletion. To repair these efficiency points, we first want the suitable instruments to measure app efficiency appropriately.
The debug construct permits you to use options helpful for improvement, like Apply Modifications, working with the debugger, or the Database Inspector. As well as, it additionally permits profiling instruments to examine the state of a working app unavailable to the discharge construct.
Below the hood, the debug construct units the debuggable flag within the Android Manifest to true.
Whereas helpful, the debug construct is supposed to offer extra info at the price of efficiency. That’s as a result of when debuggable is true, quite a lot of compiler optimizations are turned off.
To indicate you the efficiency distinction between the debug and launch builds, we recorded an app working on the identical machine however in these two construct variants. To visualise the body rendering time, we turned on Profile GPU Rendering (or Profile HWUI rendering in some Android variations) in Developer Choices when recording the display screen. Every vertical bar on the underside of the display screen represents how lengthy every body takes to render. The shorter these bars are, the smoother the animation is.
The display screen recording under exhibits the identical app working on the identical machine. The left-hand facet is on a debug construct, the right-hand facet a launch construct. The debug model has extra stuttering frames, often known as UI jank. This implies whenever you profile the debug construct, you may even see timing measurements considerably totally different from what your customers see within the launch construct, and you might find yourself optimizing one thing that isn’t the issue.
To handle that challenge, the Android platform launched a tag known as profileable. It permits many profiling instruments that measure timing info, with out the efficiency overhead of the debug construct. Profileable is accessible on gadgets working Android 10 or greater.
Let’s take a look at one other display screen recording. This time, the left facet exhibits a profileable launch app and the suitable facet an unmodified launch app. There’s little efficiency distinction between the 2.
With profileable, now you can measure the timing info way more precisely than the debug construct.
This characteristic is designed for use in manufacturing the place app safety is paramount. Subsequently we determined to solely help profiling options similar to Callstack Sampling and System Hint, the place timing measurement is crucial. The Reminiscence Profiler solely helps Native Reminiscence Profiling. The Vitality Profiler and Occasion Timeline will not be accessible. The entire listing of disabled options could be discovered right here. All these restrictions are put in place to maintain your app’s information protected.
Now that you recognize what the profileable tag does, let me present you learn how to use it. There are two choices: mechanically and manually.
Possibility 1: Use the choice in Android Studio.
With Android Studio Flamingo and Android Gradle Plugin 8.0, all you’ll want to do is simply choose this selection from the Profile dropdown menu within the Run toolbar: “Profile with low overhead”. Then Android Studio will mechanically construct a profileable app of your present construct kind and fasten the profiler. It really works for any construct kind, however we extremely suggest you to profile a launch construct, which is what your customers see.
When a profileable app is being profiled, there’s a visible indicator together with a banner message. Solely the CPU and Reminiscence profilers can be found.
Within the Reminiscence Profiler, solely the native allocation recording characteristic is accessible attributable to safety causes.
This characteristic is nice for simplifying the method of native profiling however it solely applies whenever you profile with Android Studio. Subsequently, it may nonetheless be helpful to manually configure your app in case you wish to diagnose efficiency points in manufacturing or if you happen to’re not prepared to make use of the newest model of Android Studio or Android Gradle plugin but.
Possibility 2: Guide configuration.
It takes 4 steps to manually allow profileable.
1. Add this line to your AndroidManifest.xml.
2. Swap to the discharge construct kind (or any construct kind that’s not debuggable).
3. Ensure you have a signing key configured. To stop compromising your launch signing key, you’ll be able to quickly use your debug signing key, or configure a brand new key only for profiling.
4. Construct and run the app on a tool working Android 10 or greater. You now have a profileable app. You’ll be able to then connect the Android Studio profiler by launching the Profiler instrument window and choosing the app course of from the dropdown listing.
Actually, many first-party Google apps similar to Google Maps ship their app to the Play Retailer as profileable apps.
Right here’s a desk that exhibits which construct kind ought to be used:
With these instruments offered by the Android staff, we hope you can also make your app run quicker and smoother.