[MINI GUIDE] App Optimization: Reducing Overdraw

Search This thread

alobo

Senior Member
Mar 20, 2012
163
217
Waterloo
www.oadigital.ca
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.

Enabling Profiling:

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!


Interpreting Results:

These colours have significant meaning
  • No color: No overdraw.The pixel was painted only once.
  • Blue: 1x Overdraw
  • Green 2x Overdraw
  • Light red: 3x Overdraw
  • Dark red: 4x Overdraw


Fixing The Problem:
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:

Code:
android:background="@null"

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!

Some Results:

picture.php




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!
 

molzz

Member
Nov 8, 2012
36
2
does this work with emulators?i tried checking both overdraw and gpu rendering from dev setting in 4.2 emulator but opening apps does not show me anything
 

SergeyPo

Member
Apr 22, 2013
11
0
Yes, thanks Romain Guy for this tip. Actually I would recomend to watch all videos with him -- he gives a lot of valuable hints.
 

adicool

Senior Member
Jun 25, 2011
148
27
You should not use android:background = null, rather set the background to null in your onCreate.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 34
    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.

    Enabling Profiling:

    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!


    Interpreting Results:

    These colours have significant meaning
    • No color: No overdraw.The pixel was painted only once.
    • Blue: 1x Overdraw
    • Green 2x Overdraw
    • Light red: 3x Overdraw
    • Dark red: 4x Overdraw


    Fixing The Problem:
    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:

    Code:
    android:background="@null"

    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!

    Some Results:

    picture.php




    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!