T-Mobile HTC One M8 Gets Selfie-Friendly Android 4.4.4 OTA

The T-Mobie variant of HTC One (M8) just now received an over-the-air update … more

Android L is for Lockdown

Root is, without a doubt, the (un)holy grail of the Android world. Those wonderful permissions that allow you as … more

XDA Xposed Tuesday: XHangouts Will Improve Your Hangouts

Ever since Google started supporting text messaging in Hangouts many people have … more

Shattered Screen? Turn Your Broken Device into a Complete Media Center!

A cracked screen usually means you’ll have to spend a hefty … more
Post Reply

[MINI GUIDE] App Optimization: Reducing Overdraw

OP alobo

12th August 2013, 04:38 AM   |  #1  
OP Senior Member
Flag Waterloo
Thanks Meter: 213
 
163 posts
Join Date:Joined: Mar 2012
More
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:





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!
The Following 35 Users Say Thank You to alobo For This Useful Post: [ View ]
14th August 2013, 07:52 AM   |  #2  
Junior Member
Thanks Meter: 1
 
6 posts
Join Date:Joined: Jul 2012
thanks a lot.. a will be using this on my app and see the resaults
15th August 2013, 01:45 AM   |  #3  
je2854's Avatar
Senior Member
Flag Montgomery, TX (birthplace of the Tx Flag!)
Thanks Meter: 225
 
692 posts
Join Date:Joined: Oct 2010
More
Quote:
Originally Posted by alobo

Code:
android:background="@null"

Where do you find the XML files to modify?
15th August 2013, 02:16 AM   |  #4  
officialavram's Avatar
Member
Flag World
Thanks Meter: 1
 
30 posts
Join Date:Joined: Aug 2013
-deleted-
Last edited by officialavram; 24th August 2013 at 04:51 AM.
16th August 2013, 04:37 AM   |  #5  
OP Senior Member
Flag Waterloo
Thanks Meter: 213
 
163 posts
Join Date:Joined: Mar 2012
More
Quote:
Originally Posted by je2854

Where do you find the XML files to modify?

I'm referring to your app's XML layout files, which can be found in res/layout.
16th August 2013, 01:33 PM   |  #6  
Member
Thanks Meter: 1
 
33 posts
Join Date:Joined: Nov 2012
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
18th August 2013, 05:55 AM   |  #7  
OP Senior Member
Flag Waterloo
Thanks Meter: 213
 
163 posts
Join Date:Joined: Mar 2012
More
Quote:
Originally Posted by molzz

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

Apparently you have to check 'User Host GPU' when creating your virtual device. Check this answer for more information.
19th August 2013, 12:34 AM   |  #8  
Junior Member
Thanks Meter: 0
 
2 posts
Join Date:Joined: Jan 2013
Nice! I'll check it out
2nd September 2013, 07:26 PM   |  #9  
Junior Member
Thanks Meter: 0
 
11 posts
Join Date:Joined: Apr 2013
Yes, thanks Romain Guy for this tip. Actually I would recomend to watch all videos with him -- he gives a lot of valuable hints.
24th December 2013, 04:01 AM   |  #10  
Senior Member
Thanks Meter: 27
 
147 posts
Join Date:Joined: Jun 2011
You should not use android:background = null, rather set the background to null in your onCreate.

Post Reply Subscribe to Thread

Tags
app, development, optimization, overdraw
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Java for Android App Development by ThreadRank