Sanniv Khare 6 min read

derivedStateOf to computedStateOf in Compose 1.13, measured

derivedStateOf to computedStateOf in Compose 1.13, measured

Short version: Compose runtime 1.13.0 (stable on 18 Nov 2026) adds computedStateOf, and Google now recommends it over derivedStateOf for cheap checks such as list.firstVisibleItemIndex > 0. The port is one word inside the same remember. In our test on runtime 1.13.0, both skipped the same 9 of 10 invalidations; derivedStateOf ran its calculation 11 times and cached the result, computedStateOf ran it 52 times and cached nothing. Port the one-line conditions that are read in one or two places, keep derivedStateOf for anything expensive or read many times, and remove any write to state inside the block first: in computedStateOf it throws IllegalStateException.

Why we did this: the Compose screens in our Android TV and phone apps (BMDB.fun on TV, Peepal and Shopkeeper on mobile) use derivedStateOf mostly for “show the back-to-top button” and “is this row focused” flags, exactly the case the new API targets. We wanted numbers before touching them.

What computedStateOf is

The Compose November 2026 release post introduces it as a lightweight alternative to derivedStateOf for condition checks and filtered state, and keeps derivedStateOf for heavy calculations or where caching is needed. The runtime release notes put the difference in one line: a derived state caches the result, a computed state runs the calculation on demand every time value is read. derivedStateOf is not deprecated.

The signature, from the androidx api file for runtime 1.13.0-beta01:

@StateFactoryMarker
public fun <T> computedStateOf(
    policy: SnapshotMutationPolicy<T> = structuralEqualityPolicy(),
    calculation: () -> T,
): State<T>

The KDoc in ComputedState.kt adds three rules worth knowing before you port:

  • A read is only treated as invalid when the calculation returns a value that differs from the last one read, by policy. That is what lets a composable skip recomposition, the same promise derivedStateOf makes.
  • The calculation may run more often than you read value, because the runtime also calls it to check validity.
  • It must be read-only. Since 1.13.0-beta01 (7 Oct 2026) a write to any state inside the block throws IllegalStateException, and neverEqualPolicy is called an error because it defeats the skipping.

Internally the class is about 40 lines: value runs the calculation inside Snapshot.readOnly, and isInvalidFor runs it again without read observation and compares. There is no stored result and no dependency record, which is where the “lightweight” comes from.

The port

Before and after: remember { derivedStateOf { list.firstVisibleItemIndex &gt; 0 } } becomes remember { computedStateOf { ... } }

Keep the remember. Google’s own snippets repository writes remember { computedStateOf { ... } } with the note that older Compose versions should use remember { derivedStateOf { ... } }, and androidx itself uses by computedStateOf { } on state-holder properties, where the holder is already remembered.

What we measured

We wrote a small Kotlin program against the Compose runtime alone, with no UI: a scroll index that moves from 0 to 10 in ten steps, a flag index > 0, and a SnapshotStateObserver standing in for one composable that reads the flag three times per pass. It counts how often the calculation runs and how often the observed scope is invalidated, which is what would trigger a recomposition. The core of it:

fun run(label: String, make: (() -> Int, () -> Unit) -> State<Boolean>?) {
    val index = mutableIntStateOf(0)
    var calcRuns = 0
    val flag = make({ index.intValue }, { calcRuns++ })
    var invalidations = 0
    val observer = SnapshotStateObserver { it() }
    observer.start()
    val scope = Any()
    val onChanged: (Any) -> Unit = { invalidations++ }
    fun pass() = observer.observeReads(scope, onChanged) {
        repeat(3) { if (flag != null) flag.value else index.intValue > 0 }
    }
    pass()
    for (i in 1..10) {
        Snapshot.withMutableSnapshot { index.intValue = i }
        pass()
    }
    observer.stop()
    println("%-16s calculation runs: %3d   scope invalidations: %2d"
        .format(label, calcRuns, invalidations))
}

// run("derivedStateOf") { idx, count -> derivedStateOf { count(); idx() > 0 } }
// run("computedStateOf") { idx, count -> computedStateOf { count(); idx() > 0 } }

It ran on our M1 lab Mac with JDK 17.0.21 (Zulu), Gradle 9.4.1 and Kotlin 2.4.21, depending on androidx.compose.runtime:runtime:1.13.0 (Gradle resolves the JVM variant, runtime-desktop:1.13.0). A second block writes to another state inside each calculation and catches what happens.

Output on Compose runtime 1.13.0: plain read 10 invalidations; derivedStateOf 11 calculation runs and 1 invalidation; computedStateOf 52 runs and 1 invalidation; the write throws only in computedStateOf

Output of our test run, with labels shortened and lines wrapped to fit. One machine, one run: these are counts, not timings.

What the numbers say:

  • Invalidations are the same. Reading index directly invalidated the scope on all 10 changes. Both wrappers invalidated once, on the change from false to true, and skipped the other 9. For a composable, that is the whole point of either API, and computedStateOf keeps it.
  • The calculation count is not. derivedStateOf ran 11 times: once at the start and once per change, then served the 3 reads per pass from its cache. computedStateOf ran 52 times: 33 for the 3 reads in each of 11 passes, and 19 more for validity checks after the changes, as the KDoc warns.
  • Writes differ. The same write that computedStateOf rejects with “Cannot modify a state object in a read-only snapshot” went through silently inside derivedStateOf in our test (read outside composition). Code that relied on that has to change before the port, not after.

For a comparison of two integers, 52 runs cost nothing worth measuring, and not holding a cache is the saving. For a block that filters a list of 500 titles, or a value read in ten places, the cache is what you want to keep.

Where androidx already switched

In androidx-main as of 23 Nov 2026, we counted 8 computedStateOf call sites and 51 derivedStateOf call sites across Compose foundation, Material 3 and UI. The switched ones are all cheap conditions or small lookups:

  • ScrollState in Scroll.kt: canScrollForward and canScrollBackward
  • PagerState: settledPage and targetPage
  • LazyLayoutSemanticState: the total item count
  • BasicTextField: “focused and the window is focused”
  • AndroidPopup: whether the popup position can be calculated
  • MediaQuery: the query result

The text field’s own scroll checks in TextFieldScroll.kt, the transformed text cache and the selection geometry stayed on derivedStateOf. That is the split to copy: conditions move, computed text and geometry stay.

How many candidates a real codebase has

To get a feel for the size of the job, we ran a 28-line script over four of Google’s sample repositories at their latest commits (compose-samples 16 Nov, nowinandroid 20 Oct, snippets 20 Nov, tv-samples 18 Nov 2026). It lists every derivedStateOf call and flags the ones whose body is a single-line condition:

derivedscan.py output: compose-samples 7 derivedStateOf (2 one-line conditions), nowinandroid 3 (1), snippets 18 (7) plus 2 computedStateOf, tv-samples 7 (0)

Real output of our script, regrouped onto separate lines.

Ten of the 35 calls are one-line conditions such as currentSubStack.size == 1 in nowinandroid’s navigation state or textFieldState.text.isEmpty() in Jetchat. Those are the ports. The multi-line ones, including all seven in the TV samples, need a look each: some are cheap, many map or filter collections and should stay derived. The two computedStateOf calls in snippets are Google’s own 1.13 examples.

Porting checklist

  1. Move to Compose BOM 2026.11.01 first (the release post lists Kotlin 2.2 or newer and compileSdk 37.1). computedStateOf does not exist in runtime 1.12.
  2. Search for derivedStateOf. For each call, port it when the body is a cheap comparison or lookup and value is read in one or two places.
  3. Keep derivedStateOf when the body allocates, sorts, filters or formats, or when the result is read many times per frame.
  4. Before porting, make sure the block writes nothing: no mutableStateOf assignment, no snapshot list change. In computedStateOf that is an IllegalStateException at runtime, not a compile error.
  5. Keep the default structuralEqualityPolicy(), and never pass neverEqualPolicy().
  6. Keep the remember around it inside composables.

For the other 1.13 changes, see our Compose 1.12 to 1.13 porting table and what the 1.13 click sounds change on phones and TV.

Made by the team behind this post

Apps from our studio

  • Goes with this post

    BMDB.fun

    Your Bollywood world at a glance, with links straight to the OTT app that streams each film.

    Android TV · Web · Mobile

    Get
  • Nix

    The Mac uninstaller that finds what the Trash leaves behind: caches, logs, derived data and saved states.

    macOS

    Get
  • Cardigami

    Pop-up greeting cards that rise out of the fold on iPhone Duo.

    iPhone · App Store

    Get
  • OneClick QuitAll

    Quit every running app in one click. See memory and CPU first.

    macOS · Mac App Store

    Get

Need this built? Let’s talk.

We build and run apps for Mac, TV, mobile and the web, and write about what we learn.