3. What i‘ll talk about
• How to reduce your APK size
• Memory Analysis Tools
• Performance Analysis Tools
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. „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. 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
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. 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. 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. 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
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. 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. Graphics Profilers
• 4.1+ Profiling tools
• GPU Vendor Specific
– NVIDIA [16], Qualcomm [17], Imagination
Technologies [18]
– Outside of scope of this talk
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