blog.devgenius.io 4 min read Original Source

Why Your LazyColumn Drops Frames — Part 1: Quick Fixes

Jetpack Compose’s LazyColumn and LazyRow are deceptively simple.

You’ve implemented them according to the documentation. You’ve followed all the best practices you know. Your Layout Inspector shows reasonable recomposition counts.

Yet users still report scroll jank on mid-range devices.

After optimizing Compose performance across multiple large-scale production apps and conducting countless performance reviews, I’ve discovered something critical: the real bottlenecks are the ones that look completely innocent in isolation.

This isn’t another “use keys and stable classes” article. This is Part 1 of a deep dive into the subtle, non-obvious performance traps that most of the engineers encounter

LazyColumn performance is about structure, not slow code.

It’s about understanding what Compose considers work, what triggers the composition pipeline, and how seemingly tiny decisions compound across hundreds of items.

The brutal truth: Most LazyColumn jank isn’t caused by what you’re doing wrong. It’s caused by what you don’t know you’re doing at all.

In this first part, we’ll tackle the four foundation issues that cause 80% of LazyColumn performance problems — issues you can identify and fix today.

1️⃣ Missing key — But It’s More Nuanced Than You Think

Everyone knows you should use keys. But which keys matter?

❌ The Trap: Using Database IDs as Keys

MessageCard(message)
}
}” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

// Looks correct. Causes subtle bugs.
LazyColumn {
    items(
        items = messages,
        key = { it.id }  // Database auto-increment ID
    ) { message ->
        MessageCard(message)
    }
}
// Looks correct. Causes subtle bugs.
LazyColumn {
    items(
        items = messages,
        key = { it.id }  // Database auto-increment ID
    ) { message ->
        MessageCard(message)
    }
}

The hidden problem:

When you delete item #5 and insert a new item:

  • New item gets ID #11
  • Items #6–10 shift up
  • Their positions change but IDs remain the same
  • Compose reuses nodes by ID
  • Animation state, ripple effects, and scroll anchoring break

✅ Composite Keys for Position-Dependent UI

// Combine stable identity with content versioning
"${message.id}_${message.contentHash}"
}
) { message ->
MessageCard(message)
}
}” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

data class MessageUiState(
    val id: String,
    val contentHash: Int,  // For detecting actual content changes
    val position: Int? = null  // Optional position tracking
)

LazyColumn {
    items(
        items = messages,
        key = { message ->
            // Combine stable identity with content versioning
            "${message.id}_${message.contentHash}"
        }
    ) { message ->
        MessageCard(message)
    }
}
data class MessageUiState(
    val id: String,
    val contentHash: Int,  // For detecting actual content changes
    val position: Int? = null  // Optional position tracking
)

LazyColumn {
    items(
        items = messages,
        key = { message ->
            // Combine stable identity with content versioning
            "${message.id}_${message.contentHash}"
        }
    ) { message ->
        MessageCard(message)
    }
}

🔍 The Even More Subtle Case: Paging + Keys

pagingItems[index]?.id } // ⚠️ DANGER
) { index ->
val item = pagingItems[index]
if (item != null) {
ItemCard(item)
}
}
}” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

// With Paging3, this causes massive recomposition
LazyColumn {
    items(
        count = pagingItems.itemCount,
        key = { index -> pagingItems[index]?.id }  // ⚠️ DANGER
    ) { index ->
        val item = pagingItems[index]
        if (item != null) {
            ItemCard(item)
        }
    }
}
// With Paging3, this causes massive recomposition
LazyColumn {
    items(
        count = pagingItems.itemCount,
        key = { index -> pagingItems[index]?.id }  // ⚠️ DANGER
    ) { index ->
        val item = pagingItems[index]
        if (item != null) {
            ItemCard(item)
        }
    }
}

Why this fails:

During loading states, pagingItems[index] returns null, so key becomes null. When data loads, keys suddenly become non-null, causing Compose to see them as entirely new items.

✅ Paging-Aware Key Strategy

pagingItems.peek(index)?.id ?: "placeholder_$index"
}
) { index ->
pagingItems[index]?.let { item ->
ItemCard(item)
} ?: LoadingPlaceholder()
}
}” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

LazyColumn {
    items(
        count = pagingItems.itemCount,
        key = { index ->
            pagingItems.peek(index)?.id ?: "placeholder_$index"
        }
    ) { index ->
        pagingItems[index]?.let { item ->
            ItemCard(item)
        } ?: LoadingPlaceholder()
    }
}
LazyColumn {
    items(
        count = pagingItems.itemCount,
        key = { index ->
            pagingItems.peek(index)?.id ?: "placeholder_$index"
        }
    ) { index ->
        pagingItems[index]?.let { item ->
            ItemCard(item)
        } ?: LoadingPlaceholder()
    }
}

2️⃣ Unstable Data Classes — The Recomposition Bomb

This is the #1 cause of LazyColumn performance issues

❌ The Subtle Problem

<button data-code="// Looks clean. Type-safe. Compiles perfectly.
// Recomposes catastrophically.data

class Message(
val id: String,
val sender: User, // ⚠️ Unstable
val content: String,
val reactions: List, // ⚠️ Unstable
val timestamp: Long
)

@Composable
fun MessageCard(message: Message) {
// This recomposes on EVERY scroll when any message changes
Column {
Text(message.content)
Text("From: ${message.sender.name}")
}
}” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

// Looks clean. Type-safe. Compiles perfectly.
// Recomposes catastrophically.data

 class Message(
    val id: String,
    val sender: User,  // ⚠️ Unstable
    val content: String,
    val reactions: List<Reaction>,  // ⚠️ Unstable
    val timestamp: Long
)

@Composable
fun MessageCard(message: Message) {
    // This recomposes on EVERY scroll when any message changes
    Column {
        Text(message.content)
        Text("From: ${message.sender.name}")
    }
}
// Looks clean. Type-safe. Compiles perfectly.
// Recomposes catastrophically.data

 class Message(
    val id: String,
    val sender: User,  // ⚠️ Unstable
    val content: String,
    val reactions: List<Reaction>,  // ⚠️ Unstable
    val timestamp: Long
)

@Composable
fun MessageCard(message: Message) {
    // This recomposes on EVERY scroll when any message changes
    Column {
        Text(message.content)
        Text("From: ${message.sender.name}")
    }
}

Why this isn’t obvious:

Compose’s stability inference is conservative. If it can’t prove a type is stable, it assumes instability.

List, Map, mutable properties, classes without @Immutable — all unstable.

🔍 How to Detect This (Layout Inspector)

  1. Open Layout Inspector
  2. Enable “Show Recomposition Counts”
  3. Scroll your list
  4. Watch for items recomposing even when they’re not visible

If off-screen items recompose, you have unstable parameters.

✅ Fix

Unit,
modifier: Modifier = Modifier
) {
// Only recomposes when state actually changes
Column(modifier = modifier) {
Text(state.contentText)
Text(state.formattedTimestamp)
}
}” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

@Immutable
data class MessageUiState(
    val id: String,
    val senderName: String,
    val senderAvatar: String,
    val contentText: String,
    val formattedTimestamp: String,
    val reactionCount: Int,
    val isStarred: Boolean
)

@Composable
fun MessageCard(
    state: MessageUiState,
    onReactionClick: (String) -> Unit,
    modifier: Modifier = Modifier
) {
    // Only recomposes when state actually changes
    Column(modifier = modifier) {
        Text(state.contentText)
        Text(state.formattedTimestamp)
    }
}
@Immutable
data class MessageUiState(
    val id: String,
    val senderName: String,
    val senderAvatar: String,
    val contentText: String,
    val formattedTimestamp: String,
    val reactionCount: Int,
    val isStarred: Boolean
)

@Composable
fun MessageCard(
    state: MessageUiState,
    onReactionClick: (String) -> Unit,
    modifier: Modifier = Modifier
) {
    // Only recomposes when state actually changes
    Column(modifier = modifier) {
        Text(state.contentText)
        Text(state.formattedTimestamp)
    }
}

3️⃣ Lambda Allocations in items{} — The Hidden Frame Killer

❌ The Common Pattern

MessageCard(
message = message,
onLongPress = { viewModel.onMessageLongPress(message.id) },
onReactionClick = { reaction ->
viewModel.addReaction(message.id, reaction)
}
)
}
}” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

// Everyone writes this. It allocates on every scroll.
LazyColumn {
    items(messages) { message ->
        MessageCard(
            message = message,
            onLongPress = { viewModel.onMessageLongPress(message.id) },
            onReactionClick = { reaction ->
                viewModel.addReaction(message.id, reaction)
            }
        )
    }
}
// Everyone writes this. It allocates on every scroll.
LazyColumn {
    items(messages) { message ->
        MessageCard(
            message = message,
            onLongPress = { viewModel.onMessageLongPress(message.id) },
            onReactionClick = { reaction ->
                viewModel.addReaction(message.id, reaction)
            }
        )
    }
}

What actually happens:

Every time this composable recomposes (which is often during scroll):

  • New lambda instances are created
  • Compose sees “different” parameters
  • MessageCard recomposes unnecessarily
  • Multiply this by 20+ visible items

✅ The Optimized Approach

<button data-code="@Composable
fun MessageList(
messages: List,
viewModel: MessageViewModel
) {
val onLongPress = remember Unit> {
{ messageId -> viewModel.onMessageLongPress(messageId) }
}

val onReactionClick = remember Unit> {
{ messageId, reaction -> viewModel.addReaction(messageId, reaction) }
}

LazyColumn {
items(
items = messages,
key = { it.id }
) { message ->
MessageCard(
state = message,
onLongPress = { onLongPress(message.id) },
onReactionClick = { reaction ->
onReactionClick(message.id, reaction)
}
)
}
}
}” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

@Composable
fun MessageList(
    messages: List<MessageUiState>,
    viewModel: MessageViewModel
) {
    val onLongPress = remember<(String) -> Unit> {
        { messageId -> viewModel.onMessageLongPress(messageId) }
    }

    val onReactionClick = remember<(String, String) -> Unit> {
        { messageId, reaction -> viewModel.addReaction(messageId, reaction) }
    }

LazyColumn {
        items(
            items = messages,
            key = { it.id }
        ) { message ->
            MessageCard(
                state = message,
                onLongPress = { onLongPress(message.id) },
                onReactionClick = { reaction ->
                    onReactionClick(message.id, reaction)
                }
            )
        }
    }
}
@Composable
fun MessageList(
    messages: List<MessageUiState>,
    viewModel: MessageViewModel
) {
    val onLongPress = remember<(String) -> Unit> {
        { messageId -> viewModel.onMessageLongPress(messageId) }
    }

    val onReactionClick = remember<(String, String) -> Unit> {
        { messageId, reaction -> viewModel.addReaction(messageId, reaction) }
    }

LazyColumn {
        items(
            items = messages,
            key = { it.id }
        ) { message ->
            MessageCard(
                state = message,
                onLongPress = { onLongPress(message.id) },
                onReactionClick = { reaction ->
                    onReactionClick(message.id, reaction)
                }
            )
        }
    }
}

4️⃣ Computation During Composition — The Performance Tax

❌ The Innocent-Looking Code

R.drawable.priority_high
Priority.MEDIUM -> R.drawable.priority_medium
Priority.LOW -> R.drawable.priority_low
}
)
)
}
}” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

@Composable
fun MessageCard(message: Message) {
    Column {
        Text(
            text = DateFormat.getDateTimeInstance()
                .format(Date(message.timestamp))  // ⚠️ Runs every recomposition
        )
        Text(
            text = message.content.take(100) + "..."  // ⚠️ String allocation
        )
        Image(
            painter = painterResource(
                id = when(message.priority) {  // ⚠️ Conditional logic
                    Priority.HIGH -> R.drawable.priority_high
                    Priority.MEDIUM -> R.drawable.priority_medium
                    Priority.LOW -> R.drawable.priority_low
                }
            )
        )
    }
}
@Composable
fun MessageCard(message: Message) {
    Column {
        Text(
            text = DateFormat.getDateTimeInstance()
                .format(Date(message.timestamp))  // ⚠️ Runs every recomposition
        )
        Text(
            text = message.content.take(100) + "..."  // ⚠️ String allocation
        )
        Image(
            painter = painterResource(
                id = when(message.priority) {  // ⚠️ Conditional logic
                    Priority.HIGH -> R.drawable.priority_high
                    Priority.MEDIUM -> R.drawable.priority_medium
                    Priority.LOW -> R.drawable.priority_low
                }
            )
        )
    }
}

The hidden cost:

If you have 20 items visible, and each recomposes twice during scroll, you’re:

  • Formatting 40 dates
  • Allocating 40 substrings
  • Evaluating 40 conditionals

Every scroll gesture.

✅ The ViewModel-First Solution

100) "…" else "",
priorityIcon = when(priority) {
Priority.HIGH -> R.drawable.priority_high
Priority.MEDIUM -> R.drawable.priority_medium
Priority.LOW -> R.drawable.priority_low
}
)
}

// In Composable
@Composable
fun MessageCard(state: MessageUiState) {
Column {
Text(text = state.displayTimestamp) // Just render
Text(text = state.previewText)
Image(painter = painterResource(id = state.priorityIcon))
}
}” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

// In ViewModel
data class MessageUiState(
    val id: String,
    val displayTimestamp: String,  // Pre-formatted
    val previewText: String,  // Pre-truncated
    val priorityIcon: Int  // Pre-resolved
)

private fun Message.toUiState(): MessageUiState {
    return MessageUiState(
        id = id,
        displayTimestamp = dateFormatter.format(Date(timestamp)),
        previewText = content.take(100) + if (content.length > 100) "..." else "",
        priorityIcon = when(priority) {
            Priority.HIGH -> R.drawable.priority_high
            Priority.MEDIUM -> R.drawable.priority_medium
            Priority.LOW -> R.drawable.priority_low
        }
    )
}

// In Composable
@Composable
fun MessageCard(state: MessageUiState) {
    Column {
        Text(text = state.displayTimestamp)  // Just render
        Text(text = state.previewText)
        Image(painter = painterResource(id = state.priorityIcon))
    }
}
// In ViewModel
data class MessageUiState(
    val id: String,
    val displayTimestamp: String,  // Pre-formatted
    val previewText: String,  // Pre-truncated
    val priorityIcon: Int  // Pre-resolved
)

private fun Message.toUiState(): MessageUiState {
    return MessageUiState(
        id = id,
        displayTimestamp = dateFormatter.format(Date(timestamp)),
        previewText = content.take(100) + if (content.length > 100) "..." else "",
        priorityIcon = when(priority) {
            Priority.HIGH -> R.drawable.priority_high
            Priority.MEDIUM -> R.drawable.priority_medium
            Priority.LOW -> R.drawable.priority_low
        }
    )
}

// In Composable
@Composable
fun MessageCard(state: MessageUiState) {
    Column {
        Text(text = state.displayTimestamp)  // Just render
        Text(text = state.previewText)
        Image(painter = painterResource(id = state.priorityIcon))
    }
}

The Foundation Mental Model

These four issues share a common thread: unnecessary work during composition.

The Pattern:

  1. Keys → Tell Compose what changed (identity)
  2. Stable State → Tell Compose when to recompose (stability)
  3. Hoisted Lambdas → Avoid allocation churn (allocation)
  4. Pre-computed Values → Move work out of composition (computation)

If you can’t measure the improvement, the fix isn’t real.

Continue to Part 2: Why Your LazyColumn Drops Frames — Part 2: Hidden Patterns → (Coming soon)

👉 Book time with me: 1:1

What foundation performance issues have you encountered in your LazyColumn implementations? Share your experiences in the comments.