310 likes | 401 Views
Dive into techniques for reducing APK size, utilizing memory analysis tools, and enhancing performance in Android applications. Learn how to optimize assets, manage memory efficiently, and analyze performance effectively to create smoother user experiences. Discover various tools and tips to streamline your development process and improve app efficiency for better battery life.
E N D
Who am I? [2] [1] @badlogicgames http://www.badlogicgames.com
Whati‘lltalkabout • Howtoreduceyour APK size • Memory Analysis Tools • Performance Analysis Tools
Howtoreduceyour APK size • Reduceassetsize • pngcrushyour PNGs [3] • SVG (YMMV) [4] • lower bit-rates foraudio • Reducecodesize • Remove unnecessarydependencies! • Proguard, for Class files [5] [6] • Dexguard, forDexfiles [7]
„But i can‘treducemy APK size“ • Multiple-APKs tothe „rescue“ [8] • One APK per screendensity • One APK per texturecompressionalgorithm • Use Google Play filters • EasierwithnewAndroidGradlebuildsystem • APK Expansion files [9] • hostedby Google • Roll yourown „Expansion files“ • Avoidifyoucan!
Memory Analysis Tools • „But wehave a GarbageCollector!“ • Youcan still „leak“ memory • Nastystaticvarsreferencingunusedobjects • Hidden objectreferences • Native memoryallocatedby Java classes • Ifyouwritegames, GC killsyoursteady framerate
HPROF/Eclipse MAT [11] • Select theprocess • Click • Save to a locationofyourchoice • Convertto „real“ HPROF file • Open in Eclipse MAT [12]
Performance Analysis Tools • Why do wewanttoanalyse? • Jerkyanimations • Do less, conservebattery • Betteruser Experience • What do wewanttoanalyse? • Time spent in Java code • Time spent in Native code • Time spentdrawingstuff
Beforewestart... • Never usetheemulator! • Ever, thinkofthekittens • Identifyhotspots in yourapp, not in microbenchmarks • Onlyspend time ifyouhave a real problem
Java Profilers • DDMS • Quitecapablemethodlevelprofiler • Goodenoughfor 99% ofusecases • Works withanyAndroidversion • 4.1+ Profilingtools • Systrace [13], More powerful, also tracks OS calls • Needs rootandAndroid 4.1+ • We‘llcheck out thegraphicalpartslater
DDMS • Start app • Navigatetoproblematicactivity, hit • Wait a bit, hit • View profilingdata • Ignore absolute time, onlycarefor relative timings • Ignore trivial getters/setters, instrumentationmesseswithtimings
Native Code Profilers • Android NDK Profiler [14] • Not an official NDK tool • Setup a bitinvolved • Device specific CPU profilers • NVIDIA Nsight [15], ... • Roll yourown • Instrument manually • Track down hotspots
Graphics Profilers • What do weanalyse? • Overdraw, yourbiggestenemy • Draw calls, yoursecondbiggestenemy • Use DDMS/systrace • Relatedtomemory • Textures on VRAM (whichisusually RAM) • Bitmaps in RAM
Graphics Profilers • 4.1+ Profilingtools • GPU VendorSpecific • NVIDIA [16], Qualcomm [17], Imagination Technologies [18] • Outside ofscopeofthistalk
VisualizeOverdraw • Normal Color – 0 Overdraw • Blue – 1x Overdraw • Green – 2x Overdraw • Light Red– 3x Overdraw • Dark Red– +4x Overdraw
VisualizeOverdraw • Hierarchy View [20] • Window -> Open Perspective -> Other...
VisualizeOverdraw • Tracer for OpenGL [21] • Window -> Open Perspective -> Other ... • Click • Enterpackagename • Wait
Closing Words • So muchtotell, so little time • See Dalvik Performance Tips [22] • Read all references • Yourusers will thankyouforexcellentbatterylifeandbuttery smooth UIs
FIN Thanksfor Listening Questions?
References [1] http://www.amazon.com/Beginning-Android-Games-Mario-Zechner/dp/1430246774 [2] http://libgdx.badlogicgames.com/ [3] http://pmt.sourceforge.net/pngcrush/ [4] https://code.google.com/p/svg-android/ [5] http://developer.android.com/tools/help/proguard.html [6] http://proguard.sourceforge.net/index.html [7] http://www.saikoa.com/dexguard [8] http://developer.android.com/google/play/publishing/multiple-apks.html [9] http://developer.android.com/google/play/expansion-files.html [10] http://developer.android.com/tools/debugging/ddms.html [11] http://android-developers.blogspot.co.at/2011/03/memory-analysis-for-android.html
References [12] http://www.eclipse.org/mat/ [13] http://developer.android.com/tools/help/systrace.html [14] https://code.google.com/p/android-ndk-profiler/ [15] http://www.nvidia.com/object/nsight.html [16] https://developer.nvidia.com/tegra-profiler [17] https://developer.qualcomm.com/mobile-development/mobile-technologies/gaming-graphics-optimization-adreno/tools-and-resources [18] http://www.imgtec.com/powervr/insider/sdkdownloads/ [19] http://www.curious-creature.org/2012/12/01/android-performance-case-study/ [20] http://developer.android.com/tools/debugging/debugging-ui.html [21] http://developer.android.com/tools/help/gltracer.html [22] http://developer.android.com/training/articles/perf-tips.html