Credit:
James Niccolai
Facebook is open-sourcing its Litho framework for smooth UI performance on Android mobile applications.
The framework supports native development and leverages the declarative model used in Facebook’s React UI library and the Yoga layout system. Layout operations are decoupled from Android views, which “allows us to move the CPU-intensive measure and layout operations to the background thread, saving milliseconds,” said Facebook software engineers Pasquale Anatriello and Marco Cova.
[ Get the best office apps for your Android device, and explore 10 Android apps developers will love. | Keep up on key mobile developments and insights with the Mobile Tech Report newsletter. ]
Litho’s declarative API frees developers from having to hand-optimize UIs, the engineers said. Components are laid out ahead of time in a background thread and rendered incrementally to improve performance. Facebook already has had a similar offering for Apple iOS mobile development with its ComponentKit framework.
Through Litho, complex views are broken down into smaller pieces, such as text, images, and videos, and are rendered incrementally. This spreads the work across multiple frames and recycles smaller pieces that can be recombined, thus reducing the number of views that have to be created and stored in memory. “Since being used across our apps, Litho has delivered great results, including an improvement in scroll performance of up to 35 percent, better memory behavior with complex lists, and easier-to-test UI code,” the engineers said.
Android has addressed rendering and dynamic scrolling through the RecyclerView UI container, which can recycle views, Facebook engineers said. But RecyclerView keeps views in different pools, depending on their type. This results in more views being held in memory while new views are constantly created, affecting memory and performance. A view-flattening capability in Litho reduces the number of views needing to be displayed and saves on memory.