Mugunthan
06/26/2025, 8:29 PMLazyColumn
containing multiple `LazyRow`s in Jetpack Compose on low-spec devices, even in release mode with R8.
Issue
• Setup: LazyColumn
with 10 `LazyRow`s, each with 10–15 items.
• Items Approach:
◦ Loads fast but lags on initial scroll.
◦ Smooth after "warm-up" scroll.
◦ Memory leaks may occur after prolonged scrolling.
• For Loop with Column:
◦ Loads slowly, possible memory leaks during loading.
◦ Smooth scrolling after loading.
• XML RecyclerView: Smooth loading and scrolling, no lag.
• Optimizations Tried: Stable keys, `@Stable`/`@Immutable`, Coil, release mode with R8.
Example Code
@Composable
fun LazyColumnWithLazyRows() {
val rows = List(10) { RowItem(it, "Row $it") }
val itemsPerRow = List(10) { List(10 + it % 6) { RowItem(it, "Item $it") } }
LazyColumn {
items(rows, key = { it.id }) { row ->
Text(row.title, fontWeight = FontWeight.Bold)
LazyRow {
items(itemsPerRow[row.id], key = { it.id }) { RowItemView(it) }
}
}
}
}
Questions
1. Why does the initial scroll lag on low-spec devices?
2. How to achieve RecyclerView
-like smoothness in Compose?
3. Any optimizations to reduce initial lag and memory leaks?
Suggestions appreciated!Jonathan
06/27/2025, 2:21 AMLazyColumnWithRows()
composable creates two new List
every time it recomposes. That might cause some performance issues on lower end devices. It really depends on how often LazyColumnWithRows()
gets recomposed during a scroll. Try remembering both List.Mugunthan
06/27/2025, 5:27 AM