R8: The First Step to Leaner Apps
Enabling R8 with shrink resources, the correct ProGuard file, and full mode is the single most impactful change. R8 removes unused code, minifies names, and inlines methods. Monzo, a UK digital bank with 15 million customers, enabled R8 fully. The result: a 35% reduction in application not responding rate, a 30% improvement in slow cold startup time, and a 9% app size reduction. Avoid global keep rules like `-dontoptimize` and broad package wildcards. Use the R8 configuration analyzer to inspect which rules prevent optimization.
Bitmap Optimization and Leak Detection
Bitmaps are the largest common memory objects in Android. Four practices reduce their footprint: scale down images before loading, crop out padding, use RGB_565 config when transparency is not needed, and reuse bitmaps via pools with Glide or Coil. Android Studio’s memory profiler now highlights duplicate bitmaps with a yellow triangle and preview. Leak Canary is integrated into the IDE, offering jump-to-source and copy-to-Gemini for faster fix cycles.
Profiling Manager for Android 17 Memory Triggers
Profiling Manager, introduced in Android 15, is the only API for collecting real user Perfetto profiles programmatically. Android 17 adds four new event triggers: cold start, kills due to excessive CPU, out of memory, and anomaly. The out-of-memory trigger automatically collects a Java heap dump at the moment of crash. The anomaly trigger captures a heap dump before app termination when memory exceeds a threshold. Analyze dumps in Perfetto UI to trace excessive heap usage, like string references held during file parsing.
Notable Quotes
But memory is the silent foundation those metrics are built on. Alice Yuan · ▶ Watch (0:20)
Monzo achieved a massive 35% reduction in their application not responding rate. Alice Yuan · ▶ Watch (5:57)
Bitmaps are the largest common memory objects your app will have to deal with. Fung Lam · ▶ Watch (13:16)
Profiling manager is the only API that lets you collect real user perfetto profiles programmatically. Alice Yuan · ▶ Watch (16:50)
Key Takeaways
- Enable R8 with shrink resources, correct ProGuard file, and full mode.
- Scale bitmaps, use RGB_565 config, and reuse with Glide or Coil.
- Use Profiling Manager’s out-of-memory triggers to capture heap dumps on crash.