PhonePe Ayush Bagaria May 13, 2024

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

Critical Insight

Combined with Part 1 optimizations, PhonePe reduced chat page load time (P90) from 1.5s to 750ms, a 50% improvement over 9 months.

The team hints at AsyncLayoutInflater and database redesign experiments that could push performance even further in a potential Part 3.

About This Article

Problem

PhonePe's chat feature was slow because the ViewModel kept switching threads to fetch configuration variables one at a time from SharedPreferences during startup.

Solution

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.

Impact

This configuration change, along with other improvements like removing unnecessary coroutine launches and using ViewStubs for complex layouts, helped the chat load 30% faster.