Compose compiler reports

Learn to enable and read Jetpack Compose compiler reports and metrics with the composeCompiler Gradle block to find unstable parameters in Android apps. About 25 minutes.

Why it matters

  • Compose compiler reports show, for every composable, whether it is restartable and skippable and whether each parameter is stable. They turn "why does this recompose?" into something you can read instead of guess.
  • With Kotlin 2.0+ the Compose compiler ships as the Gradle plugin org.jetbrains.kotlin.plugin.compose, and reports are configured in its composeCompiler block (reportsDestination, metricsDestination), not with old freeCompilerArgs flags.
  • Senior Android interviews often hand you a line like restartable skippable fun Row(unstable items: List<Item>) and ask what it means and whether it needs fixing.
  • Metrics give module-level counts you can compare before and after a Kotlin upgrade or a refactor of shared models.

The simple explanation

  • The compiler report is the inspection sheet a factory writes for each machine part.
  • For every composable it notes two stamps: restartable (can be re-run on its own) and skippable (can be left alone when its inputs match).
  • For every parameter it notes stable or unstable, which decides how inputs are compared.
  • The metrics file is the summary page: totals for the whole module.

What are Compose compiler reports? They are text files the Compose compiler writes during a build, describing the stability of each class and the restartable and skippable status of each composable in a module. You turn them on in the module's build.gradle.kts:

composeCompiler {
    reportsDestination = layout.buildDirectory.dir("compose_compiler")
    metricsDestination = layout.buildDirectory.dir("compose_compiler")
}
OutputFileWhat it tells you
Reports<module>-classes.txtStability of each class declared in the module, field by field
Reports<module>-composables.txtEach composable: restartable, skippable, and each parameter stable or unstable
Reports<module>-composables.csvThe composables report as CSV, for spreadsheets or scripts
Metrics<module>-module.jsonModule totals, such as skippableComposables, restartableComposables and totalComposables

The actual file names include the module and build variant (for example app_release-composables.txt). Generate them from a release build, which is what the compiler's metrics documentation recommends for accurate results.

Reading a line.

restartable skippable scheme("[androidx.compose.ui.UiComposable]") fun ArticleRow(
  unstable article: Article
  stable onClick: Function0<Unit>
  stable modifier: Modifier? = @static Companion
)
  • restartable: Compose can re-run this function by itself when state it read changes. Most composables that return Unit are restartable. Inline composables and composables that return a value are not, and @NonRestartableComposable opts out.
  • skippable: when its parent recomposes, Compose can skip it if the arguments compare equal. With strong skipping (the default from Kotlin 2.0.20), every restartable composable is skippable.
  • stable / unstable: stable parameters are compared with equals, unstable ones with === (same instance).
  • @static means the default value is a compile-time constant; @dynamic means it is computed at runtime.

So unstable article: Article is not automatically a bug. It only matters if the caller passes a new but equal Article each time, for example by mapping network models to UI models on every emission. Check classes.txt (or the class's own module) to see why it is unstable: often a List property, a var, or a class from a module built without the Compose compiler.

Notes

  • The Compose compiler is a Kotlin compiler plugin. With Kotlin 2.0+, apply org.jetbrains.kotlin.plugin.compose with the same version as Kotlin; the old composeOptions { kotlinCompilerExtensionVersion } in android { } no longer applies.
  • composeCompiler { } is a top-level block in the module build file, next to android { }. Configure it in every module whose composables you want reported, or once in a convention plugin.
  • Reports are plain text, CSV and JSON. There is no HTML report.
  • classes.txt only covers classes declared in that module. A class from another module shows up only as the stability of a parameter.
  • Under strong skipping, skippable appears on nearly every restartable function. The interesting part of the report is now which parameters are unstable and whether callers create new instances of them.
  • Before strong skipping (older Kotlin, or with it disabled), a composable with any unstable parameter was reported as restartable but not skippable.
  • stabilityConfigurationFiles takes a list of files that name classes to treat as stable, one per line, with * and ** wildcards. Example: stabilityConfigurationFiles.add(rootProject.layout.projectDirectory.file("stability_config.conf")).
  • Listing a class in the configuration file is a promise. If the class can change in ways Compose cannot see, Compose may skip a composable that should have updated.
  • Reports describe compile-time decisions. To see real recomposition counts, use Layout Inspector; to measure frames, use a Macrobenchmark.
  • Reports slow the build slightly and add files. Many teams enable them behind a Gradle property, for example only when -PcomposeReports=true is passed.

Code example

A module build file that writes reports and metrics only when asked, and reads a shared stability configuration file.

// feature/news/build.gradle.kts
plugins {
    id("com.android.library")
    id("org.jetbrains.kotlin.plugin.compose") // version set once in the root build or version catalog
}
 
android {
    namespace = "com.example.feature.news"
    buildFeatures { compose = true }
}
 
composeCompiler {
    // ./gradlew :feature:news:assembleRelease -PcomposeReports=true
    if (providers.gradleProperty("composeReports").isPresent) {
        reportsDestination = layout.buildDirectory.dir("compose_compiler")
        metricsDestination = layout.buildDirectory.dir("compose_compiler")
    }
    // One file for the whole project, passed to every module
    stabilityConfigurationFiles.add(
        rootProject.layout.projectDirectory.file("stability_config.conf")
    )
}
// stability_config.conf (project root)
// Flat, immutable models from the pure Kotlin :core:model module
com.example.core.model.Article
com.example.core.model.Author
// java.time types are immutable
java.time.Instant
  • The Gradle property keeps everyday builds free of report files; CI or a developer passes -PcomposeReports=true when needed.
  • stabilityConfigurationFiles is a list property, so add appends a file. The path points at one shared file in the project root.
  • Only small, flat, truly immutable classes are listed. A model holding a List is left out on purpose, so Compose compares it by instance instead of walking every element.

Run the idea in plain Kotlin

A small script that reads lines in the composables.txt format and lists functions with unstable parameters, the way you might check a report in CI.

val report = """
restartable skippable scheme("[androidx.compose.ui.UiComposable]") fun ArticleRow(
unstable article: Article
stable onClick: Function0<Unit>
)
restartable skippable scheme("[androidx.compose.ui.UiComposable]") fun AuthorChip(
stable name: String
)
restartable skippable scheme("[androidx.compose.ui.UiComposable]") fun TagList(
unstable tags: List<String>
stable modifier: Modifier? = @static Companion
)
""".trimIndent()

fun main() {
  var current = ""
  val unstable = linkedMapOf<String, MutableList<String>>()
  var total = 0

  for (line in report.lines()) {
      val fn = Regex("fun (\\w+)\\(").find(line)
      if (fn != null) {
          current = fn.groupValues[1]
          total++
      } else if (line.trim().startsWith("unstable ")) {
          unstable.getOrPut(current) { mutableListOf() }.add(line.trim().removePrefix("unstable "))
      }
  }

  println("Composables: " + total)
  println("With unstable parameters: " + unstable.size)
  for ((name, params) in unstable) {
      println("- " + name + ": " + params.joinToString())
  }
}

Expected output:

Composables: 3
With unstable parameters: 2
- ArticleRow: article: Article
- TagList: tags: List<String>

In production

Feed rows re-ran on every refresh even when nothing changed
  • A news feed refreshed from the network every minute. Layout Inspector showed every visible ArticleRow recomposing on each refresh, even when the articles were identical.
  • composables.txt showed unstable article: Article. Article lived in a pure Kotlin :core:model module that did not use the Compose compiler, so it could not be inferred stable.
  • The repository mapped the response to new Article objects on every refresh, so every row received a new instance and failed the === check.
The fix
  • Article is a flat data class with val fields of String, Long and Instant, so the team added it and java.time.Instant to stability_config.conf.
  • The next report showed stable article: Article, so rows now compare with equals and skip when the content is the same.
  • Layout Inspector confirmed rows no longer recomposed on an unchanged refresh.
A constant list made a header re-run on every tick
  • A dashboard had a clock that updated every second in the same composable as a CategoryTabs(labels = listOf("All", "News", "Sports")) call.
  • The report showed unstable labels: List<String>, and because listOf(...) ran in the body, each tick passed a new list, so CategoryTabs never skipped.
The fix
  • The labels moved to a top-level val CATEGORY_LABELS = listOf(...), so the same instance is passed every time and the === check succeeds.
  • The clock text moved into its own small composable, so each tick only invalidates that scope.
  • The team chose not to switch the parameter to ImmutableList: preserving the instance was enough and avoided element-by-element comparison.

Common mistakes

  • Looking for an HTML report. The compiler writes classes.txt, composables.txt, composables.csv and module.json. Open them in an editor or parse them with a script.
  • Using old freeCompilerArgs flags in a Kotlin 2.0+ project. Use reportsDestination and metricsDestination in the composeCompiler block from the Compose compiler Gradle plugin.
  • Reading reports from a debug build only. The compiler's documentation recommends release builds for accurate reports; generate them from the same variant you ship.
  • Treating every unstable parameter as a bug. Under strong skipping an unstable parameter still skips when the same instance is passed. Fix the place that creates new instances, or mark a flat model stable if it is re-created with equal values.
  • Thinking restartability is about side effects. restartable depends on the function's shape (non-inline, returns Unit, not @NonRestartableComposable), not on whether the body calls an API. Side effects in the body are a bug for a different reason: composition can run many times.
  • Listing mutable classes in the stability configuration file. If a listed class has a var or a mutable collection, Compose may skip a composable whose data changed and show stale UI.

Interview questions

Answer out loud first. Then reveal the answer and compare it at each depth.

“How do you enable Compose compiler reports, and what do they contain?”

“What does strong skipping mode change in the report?”

“A parameter is unstable because its class lives in a pure Kotlin module. What are your options?”

“What makes a composable restartable, and what does that mean?”

Quiz

Where do you configure Compose compiler reports in a Kotlin 2.0+ Android project?

With strong skipping on, the report shows restartable skippable fun Row(unstable items: List<Item>). What does it mean?

What does reportsDestination produce?

Which composable is NOT restartable?

0 of 4 answered

Mini task

Generate and read a compiler report (20 min)

  1. Add the block. In a module with composables, add composeCompiler { reportsDestination = layout.buildDirectory.dir("compose_compiler"); metricsDestination = layout.buildDirectory.dir("compose_compiler") }.
  2. Build. Run ./gradlew :<module>:assembleRelease.
  3. Open the files. In <module>/build/compose_compiler/, open the -composables.txt and -classes.txt files and the -module.json file.
  4. List candidates. Write down three composables on hot paths (list rows, frequently updated headers) that have an unstable parameter.
  5. Check the callers. For each one, find where the argument comes from. Does the caller create a new instance on every recomposition or every emission?
  6. Fix one. Preserve the instance (top-level val, remember(key), ViewModel), or, for a flat immutable model from a non-Compose module, add it to a stability configuration file.
  7. Rebuild and compare. Check that the parameter changed (if you used the configuration file) and that Layout Inspector shows fewer recompositions for that composable.

Done condition: you can explain every unstable parameter on your three composables, and one of them no longer recomposes when its data has not changed.

Next: Custom layouts and modifiers