21

I have product cell which I want to display on the list, I've used LazyColumn but performance was terrible, I couldn't find why it is so slow. Then I've switched LazyColumn to Column and all of the sudden scrolling is super smooth

LazyColumn version:

LazyColumn() {
    items(cartItems, key = {it.cartItem.id}) { cartItemData ->
        CartItemWithActions(data = cartItemData)
        Divider(color = colorResource(id = R.color.separator_line))
    }
}
 

Column version

val state = rememberScrollState()
Column(modifier = Modifier.verticalScroll(state)) {
    cartItems.forEach { cartItemData ->
        CartItemWithActions(data = cartItemData)
        Divider(color = colorResource(id = R.color.separator_line))
    }
}

CartItemWithActions is my product cell with image that I'm loading using glide and couple of texts

HWUI for LazyColumn version

HWUI for Column

Can anyone provide hint why LazyColumn is slower than Column?

UPDATE

It seems LazyColumn scroll much better when LazyColumn is setup this way

LazyColumn() {
    items(
        count = cartItems.size,
        key = {
            cartItems[it].cartItem.id
        },
        itemContent = { index ->
            val cartItemData = cartItems[index]
            CartItemWithActions(data = cartItemData)
            Divider(
                color = colorResource(id =R.color.separator_line)
            )
        }
    )
}

2 Answers2

8

It seems that initialising LazyColumn in this way solves my issue

LazyColumn() {
    items(
        count = cartItems.size,
        key = {
            cartItems[it].cartItem.id
        },
        itemContent = { index ->
            val cartItemData = cartItems[index]
            CartItemWithActions(data = cartItemData)
            Divider(
                color = colorResource(id =R.color.separator_line)
            )
        }
    )
}

However I still don't know why

3

Yes so weird noone talking about this s. Normal column like 5x faster and smooth than lazy column. Problem is when loading data in normal column freezing screen like 2 second for 50 card but after 0 freezing or slowing etc.

Nick
  • 73
  • 7
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/33538443) – Saurabh Bhandari Jan 03 '23 at 07:39