Elyes
09/07/2023, 12:50 PM@Preview
@Composable
fun TestPerformance() {
val list = remember {
List(100) { it }
}
LazyColumn(
modifier = Modifier.fillMaxSize()
) {
itemsIndexed(list, contentType = { _, _ -> 0 }) { index, item ->
TestItem(index)
Spacer(modifier = Modifier.height(10.dp))
}
}
}
@Composable
fun TestItem(index: Int) {
Surface(
color = Color.Green,
modifier = Modifier.size(100.dp)
) {
Text(text = "#$index")
}
}
ascii
09/07/2023, 1:14 PMascii
09/07/2023, 1:17 PMcausing me lag when I have an AsyncImage in my itemAre you testing on a release build? I have a UI with 400 items in a LazyColumn (no pagination). 3 Texts, 1 AsyncImage, 1 IconButton. No noticeable lag or performance issues on a 3 year old flagship, but I haven't done a proper benchmark. Debug stutters around a bit.
Elyes
09/07/2023, 1:50 PMIt’s not limited to how many items are screen-visible. See screenshot; defined in LazyListScrollPosition.ktNot sure how this relates to the issue 🤔
Are you testing on a release build?Yep I’m seeing the issue with a release build as well.
Vlad
09/07/2023, 2:04 PMascii
09/07/2023, 2:22 PMVlad
09/07/2023, 2:23 PMascii
09/07/2023, 2:24 PMVlad
09/07/2023, 2:24 PMVlad
09/07/2023, 2:26 PMAlbert Chang
09/07/2023, 2:28 PMwhen I scroll the whole page, I should find a recomposition count of 1 on each item of the new page right?No. Reusing a node is not the same as recomposing, and won’t be counted as recomposition.
Vlad
09/07/2023, 2:28 PMElyes Mansour
09/07/2023, 3:05 PMAlbert Chang
09/07/2023, 3:33 PMCould you put a few words on the difference or point me to somewhere where i can read more on the subject?I’m not sure why you are confusing them (perhaps because of
RecyclerView
?) but they are … just different things. An obvious difference is that when a node is reused, all its states are cleared (as you surely wouldn’t want a new item to inherit the states of an old item), which is not the case when it’s recomposed. If you want to know more you can read the source code of SubcomposeLayout
.
Also what about the huge number of allocations.Why not just check what the allocations are?
Also I’ve noticed the behavior where the scrolling becomes smoother after a few scrolls back and forth in the whole list. What would explain that?Likely because of JIT.
P Valintelis
09/21/2023, 6:10 AM