Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Jetpack Compose 1.6 Brings Improved Performance and Extends Supported APIs

Jetpack Compose 1.6 Brings Improved Performance and Extends Supported APIs

The latest release of Android UI toolkit Jetpack Compose aims to improve overall performance and extends supported APIs, including drag and drop, selection by mouse, spline-based keyframe animations, and more.

According to Google, Jetpack Compose 1.6 offers major performance improvements "across the board", which most apps will benefit from without any code changes just by upgrading to the latest version.

In specific areas, performance improvements are even greater. In particular, scrolling through a list of items is now 20% faster and startup time reduced by 12%, says Google. This is mostly the result of memory allocation optimizations as well as of using lazy initialization where possible to avoid not strictly required computation.

These improvements can be seen across all APIs in Compose, especially in text, clickable, Lazy lists, and graphics APIs, including vectors, and were made possible in part by the Modifier.Node refactor work that has been ongoing for multiple releases.

The Modifier.Node APIs provide a flexible, lower-level mechanism to implement custom modifiers that can be chained together to alter a composable appearance. This means that all custom modifiers created using the Modifier.Node APIs will also benefit from the same performance improvements.

Google engineers also worked on the Compose compiler plugin to optimize generated code.

Small tweaks in this code can lead to large performance improvements due to the fact the code is generated in every composable function.

In particular, the update enables the compiler to skip tracking any composable state values when not strictly required.

The new compiler also uses "intrinsic remember" by default. Remember is a state-management API that causes all stated declared using the remember keyword to be inlined and all .equals comparisons to be replaced with integer comparisons for improved speed.

[Intrinsic remember] transforms `remember at compile time to take into account information we already have about any parameters of a composable that are used as a key to remember. This speeds up the calculation of determining if a remembered expression needs reevaluating.

Another area where Google engineers worked to improve Compose behavior is automatic composable recomposition, aiming at preventing composables from being re-rendered when they should not.

Namely, a new experimental strong skipping mode attempts to deal with unstable types more effectively. Unstable types are those for which Compose cannot determine easily whether their values have changed or not between recompositions. When strong skipping mode is enabled, composables with unstable parameters will be considered to be skippable, while lambdas with unstable captures will be memoized, which Google hopes will significantly reduce undesired recompositions.

As a final note, Compose Foundation now supports platform-level drag and drop —meaning that content can be dragged between apps, and not only between views in the same app— as well as between Views and Composable objects.

About the Author

Rate this Article