OkCredit Anjal Saneen

OkCredit's OKLayoutInflater

Original post OKLayoutInflater

Article Summary

OkCredit's Android team was hitting a wall: complex XML layouts were causing frozen frames and ANRs. AndroidX's AsyncLayoutInflater wasn't cutting it.

The OkCredit engineering team built OkLayoutInflater, an open-source library that supercharges Android layout inflation using Kotlin coroutines. They tackled the limitations of AndroidX's single-threaded approach and achieved dramatic performance gains.

Key Takeaways

Critical Insight

OkCredit reduced frozen frames by 23% and improved RecyclerView performance by switching from AndroidX AsyncLayoutInflater to their coroutine-based solution.

Continue reading

What This Article Covers

Problem

AndroidX AsyncLayoutInflater uses a single background thread, which created a bottleneck. When one RecyclerView item took a long time to inflate, it blocked everything else waiting in the queue.

Solution

OkLayoutInflater switched from the single-threaded InflateThread to Kotlin coroutines with the default dispatcher. This allows layout inflation to happen in parallel across all available CPU cores.

Impact

RecyclerView load times improved significantly from the 90th percentile. Fragment opening times also got faster, dropping from the 99th percentile after switching to the coroutine-based approach.

The team shares systrace comparisons showing exactly how parallel inflation transforms scrolling performance, plus their clever workaround for view access timing issues.

This page summarizes “OKLayoutInflater” by OkCredit, published Nov 22, 2022. All credit for the original work goes to the authors.

Read the original on medium.com (opens in new tab)

AI tools for Android

Browse all AI tools →