Of Bytes, Cycles and Battery Life
Who am I?

[2]

[1]

@badlogicgames
http://www.badlogicgames.com
What i‘ll talk about
• How to reduce your APK size
• Memory Analysis Tools
• Performance Analysis Tools
How to reduce your APK size
• Reduce asset size
– pngcrush your PNGs [3]
– SVG (YMMV) [4]
– lower bit-rates for audio

• R...
„But i can‘t reduce my APK size“
• Multiple-APKs to the „rescue“ [8]
–
–
–
–

One APK per screen density
One APK per textu...
Memory Analysis Tools
• „But we have a Garbage Collector!“
– You can still „leak“ memory
– Nasty static vars referencing u...
DDMS [10] Heap View
DDMS Allocation Tracker
HPROF/Eclipse MAT [11]
•
•
•
•

Select the process
Click
Save to a location of your choice
Convert to „real“ HPROF file

•...
HPROF/Eclipse MAT
HPROF/Eclipse MAT
HPROF/Eclipse MAT
Performance Analysis Tools
• Why do we want to analyse?
– Jerky animations
– Do less, conserve battery
– Better user Exper...
Before we start...
• Never use the emulator!
– Ever, think of the kittens

• Identify hotspots in your app, not in
microbe...
Java Profilers
• DDMS
– Quite capable method level profiler
– Good enough for 99% of use cases
– Works with any Android ve...
DDMS
•
•
•
•

Start app
Navigate to problematic activity, hit
Wait a bit, hit
View profiling data
– Ignore absolute time, ...
DDMS
Native Code Profilers
• Android NDK Profiler [14]
– Not an official NDK tool
– Setup a bit involved

• Device specific CPU...
Graphics Profilers
• What do we analyse?
– Overdraw, your biggest enemy
– Draw calls, your second biggest enemy
• Use DDMS...
Graphics Profilers
• 4.1+ Profiling tools
• GPU Vendor Specific
– NVIDIA [16], Qualcomm [17], Imagination
Technologies [18...
Visualize Overdraw [19]
Visualize Overdraw
•
•
•
•
•

Normal Color – 0 Overdraw
Blue – 1x Overdraw
Green – 2x Overdraw
Light Red – 3x Overdraw
Dar...
Visualize Overdraw
• Hierarchy View [20]
• Window -> Open Perspective -> Other...
Visualize Overdraw
Visualize Overdraw
•
•
•
•
•

Tracer for OpenGL [21]
Window -> Open Perspective -> Other ...
Click
Enter package name
Wait
Visualize Overdraw
Visualize Overdraw
Closing Words
• So much to tell, so little time
• See Dalvik Performance Tips [22]
• Read all references
– Your users will...
FIN
Thanks for Listening
Questions?
References
[1] http://www.amazon.com/Beginning-Android-Games-Mario-Zechner/dp/1430246774
[2] http://libgdx.badlogicgames.c...
References
[12] http://www.eclipse.org/mat/
[13] http://developer.android.com/tools/help/systrace.html
[14] https://code.g...
Upcoming SlideShare
Loading in …5
×

Of Bytes, Cycles and Battery Life

6,311 views

Published on

Apps World 2013 talk on how to improve APK size, runtime performance and memory consumption.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,311
On SlideShare
0
From Embeds
0
Number of Embeds
4,811
Actions
Shares
0
Downloads
13
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Of Bytes, Cycles and Battery Life

  1. 1. Of Bytes, Cycles and Battery Life
  2. 2. Who am I? [2] [1] @badlogicgames http://www.badlogicgames.com
  3. 3. What i‘ll talk about • How to reduce your APK size • Memory Analysis Tools • Performance Analysis Tools
  4. 4. How to reduce your APK size • Reduce asset size – pngcrush your PNGs [3] – SVG (YMMV) [4] – lower bit-rates for audio • Reduce code size – Remove unnecessary dependencies! – Proguard, for Class files [5] [6] – Dexguard, for Dex files [7]
  5. 5. „But i can‘t reduce my APK size“ • Multiple-APKs to the „rescue“ [8] – – – – One APK per screen density One APK per texture compression algorithm Use Google Play filters Easier with new Android Gradle build system • APK Expansion files [9] – hosted by Google • Roll your own „Expansion files“ – Avoid if you can!
  6. 6. Memory Analysis Tools • „But we have a Garbage Collector!“ – You can still „leak“ memory – Nasty static vars referencing unused objects – Hidden object references – Native memory allocated by Java classes • If you write games, GC kills your steady framerate
  7. 7. DDMS [10] Heap View
  8. 8. DDMS Allocation Tracker
  9. 9. HPROF/Eclipse MAT [11] • • • • Select the process Click Save to a location of your choice Convert to „real“ HPROF file • Open in Eclipse MAT [12]
  10. 10. HPROF/Eclipse MAT
  11. 11. HPROF/Eclipse MAT
  12. 12. HPROF/Eclipse MAT
  13. 13. Performance Analysis Tools • Why do we want to analyse? – Jerky animations – Do less, conserve battery – Better user Experience • What do we want to analyse? – Time spent in Java code – Time spent in Native code – Time spent drawing stuff
  14. 14. Before we start... • Never use the emulator! – Ever, think of the kittens • Identify hotspots in your app, not in microbenchmarks • Only spend time if you have a real problem
  15. 15. Java Profilers • DDMS – Quite capable method level profiler – Good enough for 99% of use cases – Works with any Android version • 4.1+ Profiling tools – Systrace [13], More powerful, also tracks OS calls • Needs root and Android 4.1+ – We‘ll check out the graphical parts later
  16. 16. DDMS • • • • Start app Navigate to problematic activity, hit Wait a bit, hit View profiling data – Ignore absolute time, only care for relative timings – Ignore trivial getters/setters, instrumentation messes with timings
  17. 17. DDMS
  18. 18. Native Code Profilers • Android NDK Profiler [14] – Not an official NDK tool – Setup a bit involved • Device specific CPU profilers – NVIDIA Nsight [15], ... • Roll your own – Instrument manually – Track down hotspots
  19. 19. Graphics Profilers • What do we analyse? – Overdraw, your biggest enemy – Draw calls, your second biggest enemy • Use DDMS/systrace – Related to memory • Textures on VRAM (which is usually RAM) • Bitmaps in RAM
  20. 20. Graphics Profilers • 4.1+ Profiling tools • GPU Vendor Specific – NVIDIA [16], Qualcomm [17], Imagination Technologies [18] – Outside of scope of this talk
  21. 21. Visualize Overdraw [19]
  22. 22. Visualize Overdraw • • • • • Normal Color – 0 Overdraw Blue – 1x Overdraw Green – 2x Overdraw Light Red – 3x Overdraw Dark Red – +4x Overdraw
  23. 23. Visualize Overdraw • Hierarchy View [20] • Window -> Open Perspective -> Other...
  24. 24. Visualize Overdraw
  25. 25. Visualize Overdraw • • • • • Tracer for OpenGL [21] Window -> Open Perspective -> Other ... Click Enter package name Wait
  26. 26. Visualize Overdraw
  27. 27. Visualize Overdraw
  28. 28. Closing Words • So much to tell, so little time • See Dalvik Performance Tips [22] • Read all references – Your users will thank you for excellent battery life and buttery smooth UIs
  29. 29. FIN Thanks for Listening Questions?
  30. 30. 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
  31. 31. 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/toolsand-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

×