Keep an Eye on App Performance

You have an hour free, but you have so many things you could do. Why should you start profiling your app now?

Pic by Xevi Camacho with ❤

The short answer is, you probably shouldn’t. You will most likely get lost very quickly and you finish your hour with a good feeling from discovering, but also with thinking that you could fix a bug instead or refactor the class which bothers you for a long time.

Developers are busy people. There are so many things to do: features, bug fixes, refactoring and if you do find time for looking into new stuff there is simply too many skills to learn. Profiling is only one of them. Let’s have a look at how to monitor performance effectively and maybe next time you might decide to use your hour to look into it.

Performance matters … not a surprise

It is a no brainer for many of us and statistics can confirm that. Performance is important, users do notice and will like or dislike your app based on how performant it is. It is easy to know that performance matters, but it would be much better to know how much it does.

From the Google Play data recently presented at Android Dev Summit, 70% of 5-star reviews talk about performance. 40% of 1-star reviews also mention it. Statistically you will get 22% more 1-star ratings if your app has a high rate of ANRs and 52% more 1-star ratings if you have a high crash rate.

You can find 3 different talks focused directly on app performance at the Dev Summit with many others mentioning performance. One quote sums it all up:

“Quality of Android apps is increasing, you might be left behind.”

Performance is important part of the product, but there are many other things developer can focus on.

Developers may need other motivation

Most teams don’t have someone dedicated to performance and I would be curious when was the last time was that a manager asked you to improve app speed without there being a problem that was eminent. As a result the drive to investigate performance needs to come from a passionate developer.

The motivation for a passionate developer might be overall quality as well, but the goal of achieving a noticeable reduction in 1-star reviews might be too distant. Therefore I would like to stress some other reasons as to why an interested developer should dive into the profiling and monitoring world.

You learn about your app: Seeing where your app spends time in the CPU profiler or looking at memory usage can give you insight into what is happening within your app and can tell you much more than code. Many times I have been scared and amazed whilst looking into the profiler.

Seeing where your app spends time in the CPU profiler or looking at memory usage can give you insight into what is happening within your app and can tell you much more than code. Many times I have been scared and amazed whilst looking into the profiler. You learn about the Android framework: The profilers show the system code next to your own and give you insight into how Android works. Principles like Loopers and Zygote were revealed to me whilst profiling.

The profilers show the system code next to your own and give you insight into how Android works. Principles like Loopers and Zygote were revealed to me whilst profiling. You find bugs: You often notice something that is wrong. Two instances of a singleton or too many invocations of a method can lead to the discovery of a problem you had no idea existed.

You often notice something that is wrong. Two instances of a singleton or too many invocations of a method can lead to the discovery of a problem you had no idea existed. It is easier than ever before: Tools have matured. Profiling is very easy compared to how it was in the early days of Android, when it was half a day work to figure out how to display the trace file. Tools are waiting for us in Android Studio with many resources to learn them quickly.

Tools have matured. Profiling is very easy compared to how it was in the early days of Android, when it was half a day work to figure out how to display the trace file. Tools are waiting for us in Android Studio with many resources to learn them quickly. It is cool: Being cool is important. You can impress your manager with nice and colourful charts proving your findings and convince them of prioritising work on the app’s performance.

Being cool is important. You can impress your manager with nice and colourful charts proving your findings and convince them of prioritising work on the app’s performance. Your tests might run faster: This can be a very pleasant side effect of improving performance. Speeding up your app can also improve the speed and quality of your testing.

Monitor for free

Let’s say you now want to give it a try and start profiling. Maybe still too soon, we need to know where to look.

Play Store Android Vitals were introduced a year and a half ago to help us identify the problems worth to solving. One of the biggest benefits is that they give you metrics for free, simply by uploading an app to the Play Store. You also get more than just numbers, making it possible to compare your app to other apps, allowing you to see how you are really doing.

The Crash Rate benchmark, comparing your with the rest of the Play Store.

You can see these benchmarks in the Google Play Console next to each metric. Some interesting ones are Crashes, ANRs, Startup Time and many others. There are a lot of resources available to guide you through all the features of Android Vitals, so that you can get familiar with them and use them as effective monitoring tools.

Importantly, Android Vitals will also alert you when your app misbehaves and you reach a bad behaviour threshold. At such point it most likely means a problem has been introduced and that attention is needed in that area.

The Android Vitals alert. Investigation to identify crashes is necessary.

Based on the Android Vitals information you may identify the problems with your app, which you need to focus on. For example, you may see that you are in the bottom 30% of startup times, in which case you may want to start there. Conversely you may be better than 85% of other apps in that area and it can instead be a reason to celebrate or motivation to get even better.

Take action

Based on your monitoring you can actually reach a point where you know about any performance problems and it is at this point that profilers should come into play. Android Studio offers a huge variety of well-integrated tools waiting for us to use. This is where we can spare our precious hour.

Let’s say we see Android Vitals showing us our cold start is in the bottom 15% of apps. Why are we much slower than others? The CPU Profiler will give us the answer very quickly. There is even a section about startup time profiling and the whole tool is extremely well documented in general. You may discover a massive UI inflation, waiting for some file to load or some other surprising work being done on startup you had no idea about.

Forgotten ‘Thread.sleep’ in a sample app.

You may instead see a lot of frozen frames starting to appear for an activity after publishing a new version. Systrace or GPU profiling will give you more insight into what is going on. Maybe you started accidentally allocating memory in the onDraw method or there is too much overdraw occuring.

When we use monitoring to point us towards where to look, our time spent on performance can be much more effective. Sometimes the fix for a problem can be deleting one line, sometimes it may require a bigger refactor. With proper monitoring you can verify your changes made a difference and possibly see how you improved things with the next version of the app.

Monitor to find performance problems. Monitor again to verify you fixed them.

Android Vitals: Slow cold start problems introduced in version 1.9.0 and fixed in 1.10.0.

Celebrate

When Jesse Wilson talked at Droidcon NYC 2018, one important point was to eat a cake, which I consider may be the best of his points.

You can see if you improve in the Google Play Vitals benchmarks and it gives you a reason to celebrate, as you have a clear achievement. Honour the decrease in startup time or any other important metric. Have lunch, give out T-shirts, throw a party or just acknowledge the achievement. It will pay-back ten times over.

Do you like profiling, monitoring or the post just caught your attention? If so, let me know in the comments.

Happy coding and enjoy profiling!