How Grab Enhanced App Performance with R8 Optimization

Introduction
In the competitive landscape of mobile applications, performance is key. Grab, a leading ride-hailing and food delivery service in Southeast Asia, faced significant challenges with app performance, particularly regarding cold start delays and spikes in App Not Responding (ANR) errors. These issues were primarily caused by the overhead associated with reading numerous DEX files during the app’s initialization phase. To tackle these challenges, Grab implemented advanced optimization techniques that have led to remarkable improvements in their app’s performance.
Understanding the Challenges
Prior to the optimization efforts, Grab’s app experienced frequent ANR spikes after each weekly update. These spikes were particularly problematic as they affected user experience during critical journeys, such as initializing Dagger dependency graphs. While Google Play’s Cloud Profiles offered some level of optimization for standard user flows, they did not adequately address all initialization paths essential for Grab’s operations.
Implementing R8 and Profile Guided Optimization
To enhance app performance, Grab adopted R8 optimizations, Baseline Profiles, and Startup Profiles. This multi-faceted approach resulted in a significant 27% improvement in startup time and effectively eliminated post-release ANR spikes. The optimization process unfolded over three strategic phases:
- Phase One: Enabling R8 Optimization in Compatibility Mode – Grab transitioned from the legacy Proguard file to proguard-android-optimize.txt, which enabled R8 optimizations.
- Phase Two: Transitioning to R8 Full Mode – After nine months, the team shifted to R8 Full Mode, unlocking further optimizations across their extensive codebase.
- Phase Three: Refining Keep Rules – The team utilized Configuration Analyzer to enhance their keep rules, ensuring efficient optimization while maintaining app stability.
Overcoming Technical Hurdles
With a codebase exceeding a decade old and comprising over 10 million lines of code, implementing R8 posed unique challenges. The team had to address legacy configurations and specific reflection-heavy code paths. For instance, they adopted consumer keep rules from the latest Gson release to ensure seamless JSON parsing while tackling optimization challenges associated with Java dynamic proxies.
Establishing Long-term Codebase Health
Looking ahead, Grab is focused on maintaining the health of their codebase through continuous performance monitoring and strict compilation governance. By integrating the R8 Configuration Analyzer into their evaluation workflow, they can gain insights into how effectively their keep rules allow R8 to optimize, shrink, and obfuscate the application. This proactive approach is aimed at preventing regression in optimization gains across future releases.
Conclusion
Grab’s journey toward enhanced app performance through R8 optimization is a testament to the importance of continuous improvement in the tech landscape. By systematically addressing legacy code challenges and implementing a robust optimization strategy, Grab has significantly improved user experience, reduced ANR occurrences, and streamlined app startup times. As they continue to refine their processes, the focus remains on leveraging data-driven insights to ensure long-term performance excellence.
Source for the original facts: Original source.




