25
2/23/2015 Android Performance Case Study, Falcon Pro http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 1/25 Android Performance Case Study by Romain Guy www.curiouscreature.org Falcon Pro I recently installed Falcon Pro, a new Twitter client, on my Nexus 4. I really enjoy using this application but I noticed a few hiccups here and there while using it and it seemed that scrolling the main timeline did not yield a perfectly stable framerate. I dug a little bit with some of the tools and techniques I use every day at work and I was able to quickly find some of the reasons why Falcon Pro does not behave as well as it can.

Android Performance Case Study, Falcon Pro

Embed Size (px)

DESCRIPTION

Android Performance Case Study, Falcon Pro

Citation preview

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 1/25

    AndroidPerformanceCaseStudybyRomainGuywww.curiouscreature.org

    FalconProIrecentlyinstalledFalconPro,anewTwitterclient,onmyNexus4.IreallyenjoyusingthisapplicationbutInoticedafewhiccupshereandtherewhileusingitanditseemedthatscrollingthemaintimelinedidnotyieldaperfectlystableframerate.IdugalittlebitwithsomeofthetoolsandtechniquesIuseeverydayatworkandIwasabletoquicklyfindsomeofthereasonswhyFalconProdoesnotbehaveaswellasitcan.

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 2/25

    Mygoalinthisarticleistoshowyouhowyoucantrackdownandfixperformanceissuesinanapplication,evenifyoudonthaveitssourcecode.AllyouneedisacopyofthelatestAndroid4.2SDKthenewADTbundlemakessetupabreeze.Iwouldhighlyrecommendyoudownloadtheapplicationtoapplythetechniquesdescribedhereonyourown.FalconProisunfortunatelyforyouapaidapplicationandIwillthereforeprovidelinkstovariousfilesyoucandownloadtofollowmyanalysis.

    AwordaboutperformanceAndroid4.1putfocusonperformancewithProjectButteranditbroughtnewperformanceanalysistools,suchassystrace.Android4.2doesnotofferanythingassignificantassystracebutoffersacoupleofusefuladditiontoyourtoolbox.Youwilldiscoveroneofthesenewtoolslaterinthisarticle.

    Performanceanalysisisoftenacomplextaskthatrequiresalotofexperienceandadeepknowledgeofonestools,hardware,APIs,etc.Itisexperiencethatallowedmetoperform

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 3/25

    theanalysispresentedhereinonlyafewminutesyoucanseeithappeninrealtimeonmyTwitterstreamonDecember1st.Itwilllikelytakeyouafewtriesbeforeyoufeelateasewiththiskindofwork.

    ConfirmingmysuspicionsOneofthemostimportantthingstorememberaboutperformanceworkistoalwaysusemeasurementstovalidateyouractions.EventhoughitseemedobvioustomethatFalconProwassufferingfromframeratedropsonaNexus4,Ineededtomakesure.IthereforeinstalledtheapplicationonaNexus7which,whilepowerful,offersadifferentperformanceprofilethanNexus4.Nexus7offersanotherinterestingadvantageforperformanceanalysisthatwelltalkaboutlater.

    InstallingtheapplicationonNexus7didnotmakeadifferenceandIcouldstillseeframeratedrops.Itevenseemedslightlyworse.TomeasuretheproblemIdecidedtouseaProfileGPUrendering,atoolintroducedinAndroid4.1.YoucanfindthistoolintheDeveloperoptionssectionoftheSettingsapplication.

    IfDeveloperoptionsisnotavailableonyourdevicerunningAndroid4.2,gototheAboutphoneorAbouttabletsectionandtaptheBuildnumberitematthebottom7times.

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 4/25

    Withthisoptionturnedon,thesystemwillkeeptrackofthetimeittooktodrawthelast128framesofeverywindow.TousethistoolyoumustnowkillyourapplicationafutureversionofAndroidwillgetridofthisrequirement.

    Methodology:unlessspecifiedotherwise,everymeasurementinthisanalysisisdonebyslowlyscrollingthemaintimelineupanddownbyafewpixelsatatime,revealingatmostoneextralistitem.

    Afterlaunchingtheapplicationandscrollingthemaintimeline,Iranthefollowing

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 5/25

    commandfromaterminal:

    $adbshelldumpsysgfxinfocom.jv.falcon.pro

    IntheresultinglogsyouwillfindasectionentitledProfiledatainms.Thissectioncontains,foreachwindowbelongingtotheapplication,atableof3columns.Tousethisdata,simplycopythetableinyourfavoritespreadsheetprogramandgenerateastackedcolumnschart.Thechartbelowistheresultofmymeasurement(theoriginalspreadsheetcanbeviewedonline.)

    Eachcolumngivesanestimateofhowlongeachframetakestorender:

    1. DrawisthetimespentbuildingdisplaylistsinJava.ItindicateshowmuchtimeisspentrunningmethodssuchasView.onDraw(Canvas).

    2. ProcessisthetimespentbyAndroids2Drenderertoexecutethedisplaylists.ThemoreViewsinyourhierarchy,themoredrawingcommandsmustbeexecuted.

    3. Executeisthetimeittooktosendaframetothecompositor.Thispartofthegraphisusuallysmall.

    Reminder:torendersmoothlyat60fps,eachframemusttakelessthan16mstocomplete.

    Timeinmsperframe

    ExecuteProcessDraw

    0

    7

    14

    21

    28

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 6/25

    AboutExecute:ifExecutetakesalongtime,itmeansyouarerunningaheadofthegraphicspipeline.Androidcanhaveupto3buffersinflightandifyouneedanotheronetheapplicationwillblockuntiloneofthesebufferesisfreedup.Thiscanhappenfortworeasons.ThefirstoneisthatyourapplicationisquicktodrawontheDalviksidebutitsdisplayliststakealongtimetoexecuteontheGPU.Thesecondreasonisthatyourapplicationtookalongtimetoexecutethefirstfewframesoncethepipelineisfullitwillnotcatchupuntiltheanimationisdone.Thisissomethingwe'dliketoimproveinafutureversionofAndroid.

    Thechartobviouslyconfirmsmysuspicions:whiletheapplicationmostlyperformswell,itsometimesdropsaframe.

    TakingacloserlookEventhoughthedatawegatheredshowsthattheapplicationsometimestakestoolongtodraw,itdoesnttellthewholestory.Theframeratecanalsobeaffectedbyunscheduledormischeduledframes.Forinstance,ifanappalwaysdrawsinlessthan16msbutsometimesperformslongtasksbetweenframes,itwillsometimesmissaframe.

    SystraceistheeasiesttooltocheckwhetherFalconProissufferingfromthisissue.Thistoolisasystemprofilerwithverylowoverhead.Itstimingsarereasonablyaccurateandgiveyouanoverviewofwhattheentiresystemisdoing,includingyourapplication.

    Toenablesystrace,gotoDeveloperoptionsandselectEnabletraces.Adialogappears,lettingyouchoosewhattypeofeventsyouwanttoprofile.WeareonlyinterestedinGraphicsandView.

    Note:donotforgettoturnoffProfileGPUrendering.

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 7/25

    Tousesystrace,openaterminalandfromthedirectorytools/systraceintheAndroidSDK,runsystrace.py:

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 8/25

    $./systrace.py

    Bydefault,thetoolwillcaptureeventsfor5seconds.Isimplyscrolledthemaintimelineupanddown.TheresultingtraceisastandaloneHTMLdocument.

    Tip:tonavigateasystracedocument,usetheWASDkeystopanandzoom.Wwillzoominonthemousecursor.

    Asystracedocumentshowsalotofveryinterestinginformation.Forinstance,itshowsyouwhetheraprocessisscheduled,andonwhichCPU.Ifyouzoominonthelastrow,called10440:m.jv.falcon.proyoucanseewhattheapplicationwasdoing.IfyouclickononeoftheperformTraversalsblocksyoucanseehowlongtheapplicationspentdrawingaframe.

    WhilemostoftheperformTraversalsarebelowthe16msthreshold,sometakemoretime,thusconfirmingthemeasurementspreviouslyobtained(zoominatthe935msmarkertoseesuchablock.)

    Moreinterestingly,youcanseethattheapplicationsometimesmissesaframebecauseitdoesntmanagetoscheduleadrawoperation.Zoominatthe270msmarkertofindadeliverInputEventblocktaking25ms.Thisblocksindicatesthattheapplicationspent25msprocessingatouchevent.SincetheapplicationisusingaListView,thisislikelyduetoaproblemintheadapterbutwellgetbacktothislater.

    Systracewasusefultonotonlyconfirmthattheapplicationisspendingtoomuchtimedrawing,butalsotohelpusfindanotherpotentialperformancebottleneck.Itisaveryusefultoolbutithasitslimitations.Itonlyprovideshighleveldataandwemustturntoothertoolstounderstandwhatistrulygoingon.

    VisualizingoverdrawDrawingperformanceissuescanhavemanyrootcausesbutacommononeisoverdraw.Overdrawhappenseverytimetheapplicationasksthesystemtodrawsomethingontopofsomethingelse.Thinkaboutthesimplestapplicationpossible:awindowwithawhitebackgroundandasinglebuttonontopofit.Whenthesystemdrawsthebutton,itdrawsovertheexistingwhitebackground.Thatsoverdraw.

    Overdrawisinevitablebuttoomuchoverdrawcanbeanissue.Deviceshavelimitedmemorybandwidthandifoverdrawcausesyourapplicationtorequiremorebandwidth

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 9/25

    thanavailable,performancewilldegrade.Theamountofoverdrawyoucanreasonablyaffordvariesfromdevicetodevice.

    Agoodruleofthumbistoaimforamaximumoverdrawof2xthismeansyoucandrawthescreenonce,thendrawtwiceagainontop,paintingeachpixel3timestotal.

    Thepresenceofoverdrawalsousuallyindicatesotherproblems:toomanyviews,complexhierarchy,longerinflationtimes,etc.

    Androidoffers3toolstohelpidentifyandfixoverdraw:HierarchyViewer,TracerforOpenGLandShowGPUoverdraw.ThefirsttwocanbefoundinADTorthestandalonemonitortool.ThelasttoolispartofDeveloperoptions.

    ShowGPUoverdrawpaintsthescreenindifferentcolorstoindicatewhereoverdrawoccurs,andhowmuch.TurnitonnowanddontforgettokillyourapplicationafutureversionofAndroidwillremovethisrequirement.

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 10/25

    BeforewelookatFalconPro,letsseewhattheSettingsapplicationlookslikewithShowGPUoverdrawturnedon.

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 11/25

    Itiseasytointerprettheresultsifyourememberthemeaningofeachcolor:

    Nocolormeansthereisnooverdraw.Thepixelwaspaintedonlyonce.Inthisexample,

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 12/25

    youcanseethatthebackgroundisintact.

    Blueindicatesanoverdrawof1x.Thepixelwaspaintedtwice.Largeblueareasareacceptable(iftheentirewindowisblue,youcangetridofonelayer.)

    Greenindicatesanoverdrawof2x.Thepixelwaspaintedthreetimes.Mediumsizedgreenareasareacceptablebutyoushouldtrytooptimizethemaway.

    Lightredindicatesanoverdrawof3x.Thepixelwaspaintedfourtimes.Smalllightredareasareacceptable.

    Darkredindicatesanoverdrawof4xormore.Thepixelwaspainted5timesormore.Thisiswrong.Fixit.

    BasedonthisinformationyoucanseethatSettingsisawellbehavedapplicationthatdoesnotrequireanyextrawork.Thereisalittlebitofredintheswitchesbutnothingworthourefforts.

    Transparentpixels:lookcloselyatthepreviousscreenshots.Eachiconispaintedblue.Youcanseethatthetransparentpixelsofthebitmapscountagainstyouroverdraw.TransparentpixelsmustbeprocessedbytheGPUandcanbeexpensive.Androidusesoptimizationstoavoiddrawingtransparentpixelsinlayersand9patchessoyoushouldonlyworryaboutbitmaps.

    OverdrawandtheGPU:therearetwotypeofmobileGPUarchitectures.Thefirstusesdeferredrendering,forinstanceImaginationTech'sSGXseries.ThisarchitectureallowstheGPUtodetectandfixoverdrawinspecificsituations(itdoesn'tworkifyouareblendingtransparentortranslucentpixels.)ThesecondarchitectureusesimmediaterenderingandcanbefoundinNVIDIA'sTegraGPUs.Thisarchitecturecannotoptimizeoverdrawforyou,whichiswhyIliketotestonNexus7.Therearemanyadvantagesanddisadvantagestobotharchitecturesbutit'sbeyondthescopeofthisarticle.Justknowthatbothworkreallywell.

    LetsnowtakealookatFalconPro

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 13/25

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 14/25

    Thereisalotofredinthatscreenshot!Whatisinterestinghoweveristhatthelistbackgroundisgreen.Thisshowstheresa2xoverdrawbeforetheapplicationevenstartsdrawingitscontent.Theproblemweseehereismostlikelyrelatedtohavingseveralfullscreenbackgrounds.Itisusuallytrivialtofix.

    RemovingextraneouslayersToreduceoverdrawwemustfirstunderstandwhereitscomingfrom.ThisiswhereHierarchyViewerandTracerforOpenGLbeforeuseful.HierarchyViewerispartofADT(ormonitor)andcanbeusedtoinspectasnapshotoftheViewhierarchy.Itisespeciallyusefultodebuglayoutissuesbutcomesinhandyforperformanceworkaswell.

    Important:HierarchyViewerwillonlyworkonnonsecuredevicesbydefault,suchasengineeringphonesandtabletsortheemulator.TouseHierarchyVieweronanyphoneaddViewServer,anOpenSourcelibrary,toyourapplication.

    OpentheHierarchyViewerperspectiveinADT(ormonitor),thenselecttheWindowstab.Thewindowhighlightedinboldistheforegroundwindowonthedeviceandusuallytheoneyouwanttoinspect.ClickonitthenclicktheLoadbuttoninthetoolbar(itlookslikeatreeofbluesquares.)Loadingthetreecantakeawhilesobepatient.Whenthetreeisreadyyoushouldseesomethingsimilartothepicturebelow.

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 15/25

    NowthattheViewhierarchyisloadedinthetoolwecanexportitasaPhotoshopdocument.Todoso,clickthesecondbuttoninthetoolbarthetooltipsaysCapturethewindowlayers[].AdobePhotoshopitselfisnotrequiredasthegenerateddocumentiscompatiblewithtoolssuchasPixelmator,TheGIMP,etc.ThePSDfileIgeneratedisavailablefordownload.

    ThePhotoshopdocumentshowsonelayerperViewintheapplication.Eachlayerismarkedvisibleorinvisible,basedonthereturnvalueofView.getVisibility().EachlayerisnamedafteritsView,usingeithertheViewandroid:idifavailableoritsclassname.IoncestartedaddingsupportforgroupstorecreatetheViewtreeIshouldreallyfinishthisfeature.

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 16/25

    Byinspectingthelistoflayers,wecanquicklyidentifyatleastonesourceofoverdraw:multiplefullscreenbackgrounds.Thefirstoneisthefirstlayer,calledDecorView.ThisviewisgeneratedbyAndroidandcontainsthebackgroundspecifiedinthetheme.Thisdefaultgradientisinvisibleintheapplicationsoitcanbesafelyremoved.

    ScrollingupfromDecorViewyoucanseeaLinearLayoutcontaininganotherfullscreengradientbackground.ThisisthesameexactbackgroundasDecorViewsanditisthereforeunnecessary.TheonlyvisiblebackgroundthatmustremainbelongstotheViewcalledid/tweet_list_container.

    Removingthewindowbackground:thebackgrounddefinedinyourthemeisusedbythesystemtocreatepreviewwindowswhenlaunchingyourapplication.Neversetittonullunlessyourapplicationistransparent.Instead,setittothecolor/imageyouwantorgetridoffromonCreate()bycallinggetWindow().setBackgroundDrawable(null).

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 17/25

    FurtherreducingoverdrawThePhotoshopdocumentisusefultounderstandhowtheapplicationisbuiltbutitisalittlebitdifficulttousetogetridofsmalleroverdrawregions.WemustnowturntoTracerforOpenGL.OpentheperspectiveofthesamenameinADT(ormonitor)andclickthearrowiconinthetoolbar.EnterthepackagenameofyourappandthenameofthemainActivity,thenselectadestinationfileandclickTrace.

    Wordofadvice:OpenGLtracescanbehugeandreallyslowtocapture.Tomakethemsmallerandcapturefaster,uncheckalltheDataCollectionOoptionsboxes.

    Activityname:logcatwillshowthenameofthepackageandActivitywhenyoulaunchanapplication.ThisishowIknowwhattotypeinTracerforOpenGL.

    Whentheapplicationisupandrunning,turnonthefirsttwooptions:

    CollectFramebuffercontentsoneglSwapBuffers()

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 18/25

    CollectFramebuffercontentsonglDraw*()

    Thefirstoptionisusefultoquicklyfindtheframeyoureinterestedinwhilethesecondoptionallowsustoseeeachframebeingbuiltdrawingcommandbydrawingcommand.Thissecondoptioniskeytosolvingoverdrawproblems.

    WiththesetwooptionsenabledIstartedscrollingthemaintimeline.Itwillnowtakealongtimetocaptureeachframe(30secondsisnotunexpected)soIrecommendyousimplydownloadthetraceIcaptured.YoucanopenthistracefileinTracerforOpenGLbyclickingthefirstbuttoninthetoolbar.

    Onceloaded,atraceshowsyoueachGLcommandsenttotheGPUforeverycapturedframe.Ifyoudownloadedmytracefile,skiptoframe21.WhenaframeisselectedyoucanseewhatitlookslikeintheFrameSummarytab.Inaddition,youcanclickondrawingcommands,highlightedinblue,toseethecurrentstateoftheframeintheDetailstab.

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 19/25

    Organization:theGLcommandsaregroupedbyView.TheyrecreatethesametreeyoucanseeinHierarchyVieweroryourXMLlayoutfiles.ThismakesitveryeasytounderstandwhatViewgeneratedaspecificoperation.

    Byclickingsuccessivelyonthefirst3drawingcommandsyoucanseetheproblemalreadyidentifiedinPhotoshopafullscreenbackgroundisdrawn3times.

    Wecanfindmoretooptimizebylookingfurtherdownthetrace.Whenatweet(listitem)isdrawn,anImageViewisusedtodrawtheavatar.TheImageViewfirstdrawsabackgroundthentheavataritself:

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 20/25

    Ifyoulookcloselyyouwillnoticethatthebackgroundisonlyusedasaborderfortheimage.Thismeansthedarkpartinthecenteroftheavatarbackgroundcreatesoverdraw.Thatpieceofthe9patchisentirelycoveredbytheavatar.

    Averysimplefixforthisproblemistomakethestretchablecenterpieceofthe9patchtransparent.Androids2Drendereroptimizesawaytransparentpiecesin9patches.Thissimplechangewillgetridofabitofoverdraw.

    Interestingly,thesameexactproblemoccurswithinlinemedia.Avatarsaresmallsotheiroverdrawisnotabigdeal,butinlinemediacanoccupylargeareasofthescreen.Thefixisexactlythesame.

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 21/25

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 22/25

    Futureoptimization:IwouldlikeAndroid's2Drenderingpipelinetobeabletoautomaticallydetectandcorrectoverdrawforyou.WehaveafewideasbutIcannotmakeanypromise.JustaswithbuiltinGPUoptimizations,thiswouldonlyworkwithfullyopaqueprimitives.

    FlatteningtheviewhierarchyNowthatoverdrawis(mostly)takencareof,letsgobacktoHierarchyViewer.Byinspectingthetreewecantrytoidentifyunnecessaryviews.Removingviews,especiallyViewGroups,cannotonlyhelpimproveframeratebutalsomemoryconsumption,startuptime,etc.

    AquicklookatFalconProsviewhierarchyisenoughtoidentifyseveralViewGroupswithasinglechild.TheseViewGroupsareoftenunnecessaryandeasytoremove.Atleasttwoofthenodesshowninthescreenshotbelowshouldberemoved.

    Therearenumerousotherviewsthatcanberemovedfromthistree.Forinstance,eachtweetcontainsaRelativeLayoutcalledid/listElementBottom.Thislayoutcontainsthe

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 23/25

    nameoftheauthor,hisTwitterhandle,thetimeelapsedsincethetweetwaspostedandanicon.ThenameandthehandlearetwoseparateTextViewinsteadofbeingjustonewithspanstousedifferentstyles.ThetimeandtheiconuseaTextViewandanImageViewthatcouldbecombinedinasingleTextView,usingTextViewscompounddrawables.

    TheslideinmenuontheleftusesseveralgroupsofLinearLayout+TextView+ImageViewtodisplaylabelswithicons.EachoneofthesegroupscanbereplacedbyasingleTextView.

    HowtoflattenyourUI:Iexplainthesetechniquesinmoredetailinmy2009GoogleI/OtalkentitledTurbochargeyourUI.

    Whataboutinputevents?Rememberwhenwelookedatsystraceandfoundoutthattoucheventshandlingwassometimesslow?Itsnowtimetoaddressthisissueandthebesttoolatourdisposaltounderstandmoreaboutwhattheapplicationisdoingistraceview.

    TraceviewisaDalvikprofilerwhichmeasureshowmuchtimetheapplicationspendscallingmethods.Toinvokeit,opentheDDMSperspectiveinADTormonitor,selectyourapplicationprocessintheDevicestab,thenclicktheStartmethodprofilingbutton(threearrowswitharedcircle.)

    Afterenablingtracing,Iscrolledthemaintimelineupanddownandclickedthebuttonagaintofinishthetrace.Youcanalsodownloadmyowntrace.Theresultlookslikethescreenshotbelow.

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 24/25

    Clickingonitem#21,ViewRootImpl.draw(),highlightsthetimespentdrawing.Thelastcolumnofthetablegivesyouanideaoftheaveragetimespentinthismethodandallitschildren.Ifyoulookcloselyatthetimeline,withthehighlights,youwillnoticegapsbetweensuccessiveframes.

    Aneasywaytofigureoutwhatsgoinginduringthesegapsistozoominatthebeginningofonethemandclickthelargestcoloredblockyoucanfind.Youcanthenfollowtheparentchainuntilyoufindsomethingyourecognize.Inmycase,IfollowedacalltoPattern.compileImpl,takinganaverageof0.5ms,allthewayuptoDBListAdapter.bindView.

    Obviouslytheapplicationrecompilesthesameregularexpressionoverandoveragain,everytimeanewitemisboundwhilescrollingthemaintimeline.TraceviewshowsthatbindViewtakes38msonaverageand56%ofthattimeisspentparsingHTMLtext.This

  • 2/23/2015 AndroidPerformanceCaseStudy,FalconPro

    http://www.curiouscreature.com/docs/androidperformancecasestudy1.html 25/25

    seemslikesomethingthatcouldbeachievedinthebackgroundinsteadofblockingtheUIthread.andofcourse,theregexshouldnotberecompiledeverytime.

    Itsyourturn!Ikeptonelasttraceasanexercise.Theapplicationhastwoslideinmenusthatcanbeunveiledbyswipingthetimelineleftorright.ShowGPUoverdrawshighlightsanexcessiveamountofdrawingduringtheswipesandIusedTracerforOpenGLtocaptureseveralframesofaswipe.Downloadmytraceandseeifyoucanfigureoutwhatscausingtheoverdraw(gotoframe#34.)

    Hints:theapplicationshouldusehardwarelayersbycallingView.setLayerType()tosimplifydrawing.Therearealsoextraneousbackgroundsthatcanbeoptimizedawaywithcleveruseof9patches.Clippingcouldalsobeveryhelpful.Finally,maybeaColorFiltersetonaPaintpassedtosetLayerType()couldhelpremovethelastdrawingcommand.

    Ishowedyouvarioustoolsyoucanusetooptimizeyourapplications.Icouldspendalotoftimedescribingwhattechniquestousetosolveissuesidentifiedwiththesetoolsbutthisarticlewouldturnintoabook.CheckoutthereferencedocumentationoftheofficialAndroiddeveloperswebsiteandalltheGoogleI/OAndroidtalks(slidesandvideosareavailableonlineforfree.)

    RomainGuywww.curiouscreature.org