Refactor: Prefetching data
Before:
- Data is fetched only after the fragment is created.
- Unrelated operations in the fragment run before the network call.
After:
- Data is prefetched in parallel with fragment creation, reducing latency by 300-400ms and increasing revenue by 3-4%.
- Kotlin StateFlow performs well but requires a broader lifecycle context than a fragment, deviating from standard Android patterns.
The optimizations
The first step in prefetch for this page was to find a path outside the normal MVVM pattern. While refactoring to accomodate the new code, I was able to improve our fragment's adherance to best practices.