PhonePe Ayush Bagaria Mar 15, 2024

Enhancing Chat Performance on PhonePe Android - Part 1

Article Summary

Ayush Bagaria from PhonePe set out to cut chat latency by 50% in their P2P payment flow. The journey taught some expensive lessons about the gap between POC results and production reality.

PhonePe's Android team tackled performance issues in their peer-to-peer payment chat feature, one of their most critical user flows. This first installment covers three optimization approaches: debugging slow database queries, experimenting with deserialization libraries, and implementing pagination.

Key Takeaways

Critical Insight

These three approaches collectively improved latency by 20%, with the biggest lesson being that POC performance gains don't always translate to production environments.

Part 2 promises another 30% improvement through CPU profiling and thread pool optimization techniques.

About This Article

Problem

PhonePe's chat roster was loading entire chat lists from the database and rendering them all in RecyclerView, even though users only saw 6-8 threads at a time. For users with over 10,000 chat threads, this meant the app wasted resources transforming data that would never appear on screen.

Solution

Ayush Bagaria's team added Android's paging library to load chat data in chunks instead of all at once. This cut down on database queries and reduced the number of UI elements the app had to create.

Impact

Chat roster load time dropped by 30-33% at P90. Latency fell from 3-3.4 seconds to 2-2.3 seconds. The change opened the door for further performance improvements down the line.