LazyColumn with Multiple LazyRows Performance Issu...
# compose
m
LazyColumn with Multiple LazyRows Performance Issue I'm facing performance issues with
LazyColumn
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
Copy 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!
j
I'm not sure if it's causing your performance issue but your
LazyColumnWithRows()
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.
m
@Jonathan Thanks for your reply, yes I have tried using remember even though the issue still persists, that's happening on my Android TV devices