Compose compiler reports
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 itscomposeCompilerblock (reportsDestination,metricsDestination), not with oldfreeCompilerArgsflags. - 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")
}| Output | File | What it tells you |
|---|---|---|
| Reports | <module>-classes.txt | Stability of each class declared in the module, field by field |
| Reports | <module>-composables.txt | Each composable: restartable, skippable, and each parameter stable or unstable |
| Reports | <module>-composables.csv | The composables report as CSV, for spreadsheets or scripts |
| Metrics | <module>-module.json | Module 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
Unitare restartable. Inline composables and composables that return a value are not, and@NonRestartableComposableopts 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). @staticmeans the default value is a compile-time constant;@dynamicmeans 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.composewith the same version as Kotlin; the oldcomposeOptions { kotlinCompilerExtensionVersion }inandroid { }no longer applies. composeCompiler { }is a top-level block in the module build file, next toandroid { }. 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.txtonly covers classes declared in that module. A class from another module shows up only as the stability of a parameter.- Under strong skipping,
skippableappears on nearly every restartable function. The interesting part of the report is now which parameters areunstableand 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
restartablebut notskippable. stabilityConfigurationFilestakes 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=trueis 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=truewhen needed. stabilityConfigurationFilesis a list property, soaddappends 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
Listis 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
- A news feed refreshed from the network every minute. Layout Inspector showed every visible
ArticleRowrecomposing on each refresh, even when the articles were identical. composables.txtshowedunstable article: Article.Articlelived in a pure Kotlin:core:modelmodule that did not use the Compose compiler, so it could not be inferred stable.- The repository mapped the response to new
Articleobjects on every refresh, so every row received a new instance and failed the===check.
Articleis a flat data class withvalfields ofString,LongandInstant, so the team added it andjava.time.Instanttostability_config.conf.- The next report showed
stable article: Article, so rows now compare withequalsand skip when the content is the same. - Layout Inspector confirmed rows no longer recomposed on an unchanged refresh.
- 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 becauselistOf(...)ran in the body, each tick passed a new list, soCategoryTabsnever skipped.
- 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.csvandmodule.json. Open them in an editor or parse them with a script. - Using old
freeCompilerArgsflags in a Kotlin 2.0+ project. UsereportsDestinationandmetricsDestinationin thecomposeCompilerblock 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
unstableparameter 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.
restartabledepends on the function's shape (non-inline, returnsUnit, 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
varor 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)
- Add the block. In a module with composables, add
composeCompiler { reportsDestination = layout.buildDirectory.dir("compose_compiler"); metricsDestination = layout.buildDirectory.dir("compose_compiler") }. - Build. Run
./gradlew :<module>:assembleRelease. - Open the files. In
<module>/build/compose_compiler/, open the-composables.txtand-classes.txtfiles and the-module.jsonfile. - List candidates. Write down three composables on hot paths (list rows, frequently updated headers) that have an
unstableparameter. - 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?
- 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. - 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.