Designing and implementing a user interface that can perform dynamically and consistently across a broad range of mobile devices is hard, but Facebook is aiming to make it a bit easier for all by open-sourcing the Litho framework that they created from scratch to handle scrolling workloads for Android apps. Litho is loosely based on the principles that Facebook used when writing their mobile UI in ReactJS, and it’s a declarative framework that uses the Yoga layout manager to bring scalable performance to rendering while taking a somewhat similar approach to Android’s built-in RecyclerView. Essentially, Litho breaks the scrolling workload down into smaller pieces and dynamically calculates what needs to be freshly drawn and what can be reused, as well as what needs to be prioritized in order to render a new frame in the 16ms window given by modern devices’ 60Hz refresh rates.
Litho works in a pretty unique way; to put it in the simplest terms, it takes the scrolling render workload away from its usual place in the Android stack, then disassembles that workload and makes it as efficient as possible. As a bonus, Litho moves as much of the workload as possible to a background thread, leaving the foreground processes to do the heavy lifting and take care of more dynamic elements of the user interface. Page elements like text, images, and plugin-generated content are all broken into individual parts and rendered by priority according to their placement on the page, among other factors.
Since implementing Litho for themselves, Facebook has reported up to 35-percent better scrolling performance in their app, their code has been easier to test, and the app has exhibited better behavior in regards to memory-intensive tasks like rendering long item lists. Litho is fully open source and is delivered as a completely optimized, ready-to-use API. Facebook’s announcement didn’t say whether it can actually be implemented into existing code, but with the code all being readily laid out, one would be remiss to say it would be hard to implement into just about any project involving heavy scrolling-related workloads. It’s now available on GitHub and can be used and improved by anyone. Facebook is also hosting resources to help developers learn to use Litho, which you can find by following the source link below.