How PhonePe Enhances Chat Performance on PhonePe Android - Part 2
Original post Enhancing Chat Performance on PhonePe Android - Part 2
Article Summary
Ayush Bagaria from PhonePe reveals how CPU profiling and thread optimization slashed chat load times by 30%. Most Android apps are sitting on similar performance gains.
This is Part 2 of PhonePe's deep dive into optimizing their Android chat experience. After achieving 20% improvement through database and pagination fixes (Part 1), the team turned to CPU profiling and thread management to squeeze out even more performance.
Key Takeaways
- Replaced postValue() with setValue() in LiveData to eliminate unnecessary Handler.post() calls
- All databases shared one 4-thread executor pool, creating massive bottlenecks
- Separated database executors and paging library threads for parallel execution
- View stubs and lazy dependency injection reduced fragment inflation time
- Passing metadata between screens eliminated redundant database fetches for 60% of users
Combined with Part 1 optimizations, PhonePe reduced chat page load time (P90) from 1.5s to 750ms, a 50% improvement over 9 months.
Continue reading
What This Article Covers
PhonePe's chat feature was slow because the ViewModel kept switching threads to fetch configuration variables one at a time from SharedPreferences during startup.
The team built a custom configuration class that holds all the variables as members. This let them fetch everything from SharedPreferences in a single operation, cutting out the extra thread switches.
This configuration change, along with other improvements like removing unnecessary coroutine launches and using ViewStubs for complex layouts, helped the chat load 30% faster.
This page summarizes “Enhancing Chat Performance on PhonePe Android - Part 2” by PhonePe, published May 13, 2024. All credit for the original work goes to the authors.