Skip to content

Instantly share code, notes, and snippets.

@LethalMaus
Created March 13, 2026 20:10
Show Gist options
  • Select an option

  • Save LethalMaus/46c71aa74756b2c9deb8d2b9602b5838 to your computer and use it in GitHub Desktop.

Select an option

Save LethalMaus/46c71aa74756b2c9deb8d2b9602b5838 to your computer and use it in GitHub Desktop.
Recomposition overlay snippet for Android app startup article
@Composable
private fun RecomposeDebugOverlay(modifier: Modifier = Modifier) {
if (!BuildConfig.DEBUG) return
val counts by RecomposeDebugTracker.counts.collectAsStateWithLifecycle()
var expanded by rememberSaveable { mutableStateOf(false) }
Surface(modifier = modifier.clickable { expanded = !expanded }) {
Column(modifier = Modifier.padding(horizontal = 12.dp, vertical = 8.dp)) {
Text(text = "Recompose ${if (expanded) "hide" else "show"}")
if (expanded) {
counts.toList().sortedBy { it.first }.forEach { (name, count) ->
Text(text = "$name: $count")
}
TextButton(onClick = { RecomposeDebugTracker.reset() }) {
Text(text = stringResource(id = R.string.clear))
}
}
}
}
}
@Composable
private fun DebugRecomposeCounter(section: String) {
if (!BuildConfig.DEBUG) return
SideEffect {
val count = RecomposeDebugTracker.increment(section)
if (count % 25 == 0) {
Log.d("Recompose", "$section recomposed $count times")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment