[MINI GUIDE] App Optimization: Reducing Overdraw
Hey XDA - I just wanted to share some useful information I came across while developing my app:
App performance is crucial if you want your users to enjoy using your app - the goal is to reduce lag.
There are many ways one can achieve this:
- Using multithreading
- Simplifying View hierarchy
- Reducing Overdraw
Pixel Overdraw occurs when an app repaints a pixel multiple times. This is something we don't really think about, but can have a massive effect on our performance.
Fortunately, Android has some built in tools to help us developers. (You can find these under Developer Settings)
You'll want to turn on:
1) Force GPU Rendering
2) Show GPU Overdraw
Next, simply restart the app you want to profile and voila - areas of the screen are 'painted' in a variety of colours!
These colours have significant meaning
Fixing The Problem:
- No color: No overdraw.The pixel was painted only once.
- Blue: 1x Overdraw
- Green 2x Overdraw
- Light red: 3x Overdraw
- Dark red: 4x Overdraw
You'll want to dig in your XML layout files and look for areas of overlap. The biggest issue is if you are drawing backgrounds on top of each other. In my case, my app was drawing 4 backgrounds: one for the activity, one for the fragment, one for the ListView and one for the list item. Then text was drawn on top. As the the image at the bottom of this post suggests, it wasn't pretty.
The solution was simple:
I simply removed the unnecessary backgrounds.
Your solutions may not be as easy, but it doesn't hurt to give it a try. In fact, the scrolling performance of my app improved dramatically - it's now buttery smooth!
Credits to Romain Guy. He has a full tutorial on his blog that you should definitely check out.
Please let me know what worked for you and do share any tips you have to optimize app performance!