Home / Companies / RevenueCat / Blog / Post Details
Content Deep Dive

Mark your models as stable with the Compose runtime annotation library

Blog post from RevenueCat

Post Details
Company
Date Published
Author
Jaewoong Eum
Word Count
1,110
Language
English
Hacker News Points
-
Summary

In Jetpack Compose, stability is crucial for optimizing recomposition and UI performance, as stable objects allow the framework to skip unnecessary recompositions. Challenges arise when classes, even those with stable types, are marked as unstable if they originate from different packages, complicating multi-module architectures and library development. The newly introduced compose-runtime-annotation library offers a solution by providing stability annotations like @Immutable and @Stable without adding full Compose dependencies to unrelated modules. This library, designed for Kotlin Multiplatform, allows developers to mark classes as stable at compile time, improving performance without runtime overhead. A practical example is RevenueCat’s Android SDK, which adopted this library to enhance UI stability. While the Compose Stable Marker library served similar purposes before, the official library is preferred, although it requires a compileSdkVersion of at least 34. Additional strategies for improving stability include using a stability configuration file and enabling Strong Skipping mode, which can enhance stability without annotations but may not be sufficient for all scenarios, particularly in library development where explicit stability guarantees are recommended.