Consider a screen where there is scrolling content, parallax images, and a button which pops up once the user scrolls downwards.These three elements are scroll-state-dependent but don’t necessarily need updates to the same extent.The parallax effect must keep on updating according to the position of the scrollbar. The floating button will only require that it checks if the user is past a certain point, not where every single pixel is.However, an implementation of Compose that follows the simple approach results in both components getting composed each time the state below changes.It is not about the number of composables and their complex layout structure; it is about the place where state is being read and if every change is essential for the UI or not.Compose offers two great solutions to this issue: derived state or computed state, which selects the changes based on the values they produce; and deferred state reads, which observe states at a later rendering stage.These two are solutions to two different issues. Knowing this makes for better performance choices than simply trying to minimize recomposition numbers.Recomposition is only part of the rendering pipelineCompose renders UI through three primary phases:Composition: Determines what UI elements should exist.Layout: Measures elements and determines where they should be placed.Drawing: Renders the elements onto the screen.Compose tracks snapshot state reads within these phases. When a state value changes, it uses the recorded dependencies to determine which work needs to run again.For example:var padding by remember { mutableStateOf(8.dp)}Text( text = "Hello", modifier = Modifier.padding(padding))The padding state is read while constructing the modifier during composition. A change to that value invalidates the relevant composition scope.Now consider a different situation: an image whose position changes while scrolling.The contents, dimensions, and looks could stay the same; only its position should change.Why would we need to do composition again in order to get something related to layout?That’s why state reads are deferred in Compose. Compose does not need all the states’ values during composition.The location where a state object is created doesn’t determine the rendering phase. The location of its value read does.Smart recomposition: React to meaningful changes, not every input changeConsider the floating button in our scrolling example.A basic implementation might look like this:@Composablefun ScrollToTopButton( listState: LazyListState) { val showButton = listState.firstVisibleItemIndex > 0 if (showButton) { ScrollToTopButtonContent() }}This code is perfectly valid.But the fact that the composable reads firstVisibleItemIndex directly when being composed means that the composable becomes an observer of changes to that state. During scrolling, the state of the list may change quite often.The button doesn’t have to react to all those updates under the hood. It has to know only whether the first visible item index is greater than zero.It is a perfect example of the state derivation problem.Introducing computedStateOfCompose Runtime 1.13.0, released on November 18, 2026, introduces computedStateOf as an alternative to derivedStateOf.The API creates a State backed by a calculation that can read other state objects. Its important property is that readers are invalidated when the calculation's result changes, rather than whenever one of its input states changes.We can rewrite the example:@Composablefun ScrollToTopButton( listState: LazyListState) { val showButton by remember { computedStateOf { listState.firstVisibleItemIndex > 0 } } if (showButton) { ScrollToTopButtonContent() }}Now suppose the user scrolls past a few items.The scroll state underneath keeps changing, but the calculated result remains true. The button doesn't need another composition pass for those changes.When the calculated result changes from false to true, Compose invalidates the observer so that the UI can display the button.This gives us a useful distinction:Input state represents what is changing.Computed state represents which changes matter to a particular UI decision.The important detail is that computedStateOf does not cache the calculation result. It evaluates the calculation whenever its value is read, and it uses the supplied mutation policy (structural equality by default) to determine whether the result has changed.It will be ideal for performing cheap computations like Booleans, threshold, and light weight transformations.The calculation must also remain read-only. It shouldn’t perform side effects or modify other state objects.Should you replace every derivedStateOf?No. The two APIs have different performance characteristics.The computed result is cached byderivedStateOf. It makes sense to use it when the computation is resource-intensive or its result is accessed more than once.computedStateOf avoids that caching overhead and recalculates on demand.For a simple condition such as:listState.firstVisibleItemIndex > 0caching may cost more than evaluating the condition itself.If you want to use caching in case of an object allocation operation, multiple state inputs, or any expensive operation, then it is always useful.A practical selection rule is:Use computedStateOf for lightweight derivations driven by frequently changing state.Use derivedStateOf when repeated reads can benefit from cached calculations.Use a normal Kotlin property or getter when you don’t need to filter invalidations at all.In case of the projects that have Compose Runtime below 1.13 version, it will be better to go with derivedStateOf.Deferred state reads: Move the dependency to the phase that needs itThe problem solved by the state derivation approach is that not all changes in the input have to invalidate the UI.What about the case when all input changes matter?We need our parallax image to move in response to the scroll. Any kind of filtering will ruin that behavior.Instead, we have to modify the place from which we read the state in Compose.Consider this implementation:Modifier.offset( with(LocalDensity.current) { (listState.firstVisibleItemScrollOffset / 2).toDp() })Here, the scroll offset is read during composition. The calculated value is passed directly to the value-based Modifier.offset overload.As the user scrolls, the state changes and the composition scope is invalidated. Compose then performs the subsequent rendering work.The image only needs a new position, though. Its content hasn’t changed.Compose provides a lambda-based overload that moves the read into the placement step of Layout:Modifier.offset { IntOffset( x = 0, y = listState.firstVisibleItemScrollOffset / 2 )}The distinction is not purely syntactic.The lambda runs at the layout placement stage. The compose framework now knows about the scroll status at this stage, allowing the placement to restart without recomposing.The measurement step may be skipped if the modification only affects the placement process.This is especially useful for scrolling, parallax animations, and other position-based animations.Drawing can be deferred even furtherNot every frequently changing property affects layout.Consider an animated alpha value:@Composablefun FadingContent( targetAlpha: Float) { val alpha = animateFloatAsState( targetValue = targetAlpha, label = "contentAlpha" ) Box( modifier = Modifier.graphicsLayer { this.alpha = alpha.value } )}It is important to mention that the animation’s result will be kept in the State and not extracted through property delegation during composition.The read takes place inside the graphicsLayer lambda.In this case, Compose does not need to perform any Composition and Layout, but instead, updates the drawing layer.This concept is used for other drawings as well, such as drawBehind and drawWithContent.The appropriate phase depends on what the state actually changes:Content or UI structure changes belong in Composition.Position changes can often be handled in Layout.Visual properties such as alpha, rotation, and scale can often be handled in Drawing.The Modifier breakdown by phase documents which modifier overloads evaluate their arguments in each phase.These optimizations solve different problemsIt is important to keep these two methods distinct.Recall the scrolling screen from before.The floating button has a visibility criterion that is threshold-based. It does not have to respond to every single scroll event. computedStateOf filters the state updates such that the composition will respond only when the value changes.The parallax image has a different requirement. It needs every relevant scroll update, but those updates only affect its position. A lambda-based Modifier.offset moves the state read into Layout.One reduces unnecessary invalidations. The other avoids running earlier rendering phases when they aren’t needed.You can use both in the same screen without introducing special scheduling logic or manually coordinating recomposition.Then there’s also an important limit — shifting the read to a later phase doesn’t mean that every UI change is now appropriate for deferred work. If the read affects whether a composable appears at all, what text appears, or what content appears, then composition must also be part of the process.The idea is not to move everything to Drawing. It is to shift every read to the last phase that can properly communicate the needed change.How do you know the optimization is worthwhile?One such error that often occurs is using recomposition counts to directly measure performance.An efficient composable recomposing is not necessarily expensive. Similarly, even an efficient composable that only recomposes once might incur jank due to doing expensive work on the main thread.In Android’s Compose tooling guidelines, this is clearly pointed out: the number of recompositions is not a replacement of performance measurement. There are also costs involved in skipping composable with their own parameters and slot tables.For investigation, I would use three tools for different purposes:Layout Inspector helps identify which composables are recomposing and whether the observed behavior matches expectations.Perfetto composition tracing helps establish how much time composition actually takes and where the rendering work occurs.Macrobenchmark provides a way to measure user journeys and compare performance before and after an optimization.Composing Runtime Tracing 1.13.0 also features Recomposition Tracing that provides state read/write events in Perfetto traces. A state write can be related to the recomposition event it triggers along with the corresponding call stack.There is an important condition though: recomposition tracing imposes additional overhead. It should be used for investigating reasons and then disabled for performance measurement.Stop optimizing recomposition in isolationA useful way to approach Compose performance is to ask two questions before changing the implementation:Does every input change represent a meaningful UI change?When the answer is no, consider deriving a smaller state that filters irrelevant updates.Does the UI need composition to respond to this change?When the answer is no, consider moving the state read into the Layout or Drawing phase.These decisions impact distinct portions of Compose’s rendering pipeline. computedStateOf helps determine when an input change is worth considering. lambda modifier helps determine when it is time for UI to do something.This goal makes more sense compared to eliminating all recompositions from the process.There is no need for Compose to have less frequent updates regardless of the price. It has to have the correct update at the right time for the right reason.Smart Recomposition in Jetpack Compose: Computed State and Deferred Reads was originally published in ProAndroidDev on Medium, where people are continuing the conversation by highlighting and responding to this story.
Smart Recomposition in Jetpack Compose: Computed State and Deferred Reads
Smart Recomposition in Jetpack Compose: Computed State and Deferred Reads
Editor
Dec 3, 2026 · 10 min read

From other categories

Databases
How Atlan Moved Its Data Platform from Spark and StarRocks to DuckDB on S3
just now·7 min

Security
Lunex Stealer Targets European Hospitality Firms With Fake Google Translate Extension
just now·1 min

Operating Systems
FreeCAD 26.3 Open-Source 3D Parametric Modeler Released, Here’s What’s New
1h ago·1 min

Hardware
Save $90 on this 3-item gaming combo with Ryzen 7 5800X3D, 32GB RAM, and Asus TUF Gaming motherboard from Newegg
1h ago·4 min

AI & Machine Learning
Intuit and OpenAI build NightFalcon to secure complex workflows
3h ago·1 min

Programming Languages
Handling Irreducibility in a Just-in-Time Compiler
17h ago·1 min