Does anyone knows how `item{}` works in LazyColumn...
# compose
t
Does anyone knows how
item{}
works in LazyColumn? I’m having a weird issue with it If i have 2
item
block inside a LazyColumn when i scroll pass the all the elements in the first item block and scroll back to it, all the composable in the first item block got recomposed even if the data haven’t changed.
Here’s an example
Copy code
LazyColumn(
            modifier = Modifier
                .fillMaxSize()
                .padding(bottom = 48.dp)
        ) {
            item {
                Account()
                Lessons()
                Schedule()

            }
            item {
                LazyColumn(
                    modifier =             Modifier.height(500.dp)
                ) {
                    items(lessons) { lesson: Lesson ->
                        LessonScheduleView(
                            item = lesson,
                            modifier = Modifier
                                .fillMaxWidth()
                        )
                    }
                }
                NewsList()
                Products()
                FollowUs()
            }
        }
whenever I scroll pass
Schedule()
and scroll back again all
Account()
,
Lessons()
and
Schedule()
get recomposed
But if I do this it worked fine
Copy code
LazyColumn {
     item {
                Account()
                Lessons()
                Schedule()
                LazyColumn(
                    modifier =             Modifier.height(500.dp)
                ) {
                    items(lessons) { lesson: Lesson ->
                        LessonScheduleView(
                            item = lesson,
                            modifier = Modifier
                                .fillMaxWidth()
                        )
                    }
                }
                NewsList()
                Products()
                FollowUs()
            }
}
a
that is how LazyColumn works in general. lazy means here that we only compose items which are visible. so once some item is not visible anymore it is disposed and then composed again when visible
t
It’s seems a bit laggy when recomposing those 3 composable
1
and it gets worse when i split each of the composable into it’s own
item{}
block
a
LazyColumn is basically a RecyclerView. there you would see similar issues. And yes, performance for such complex things is not yet final, we are looking on ways to improve it
please also consider testing the performance on the release builds. debug builds are not representing the real performance
a
Can you share the code for those particular composables that are slow to compose? Account/Lessons/Schedule?
t
Sure! Here u are. I copy all the code into one file so it’ll be a little bit messy 😄
a
thanks!
a
Thanks! I filed a bug for us to investigate: https://issuetracker.google.com/issues/182381949
t
Thank you!