perf: avoid O(N^2) indexOf in notifications list

Replace items(...) + notifications.indexOf(item) with itemsIndexed(...)
in NotificationsScreen. The indexOf call ran during composition for
every visible item, causing a linear scan per item and quadratic total
work as the list grew. Reported as a UI freeze when tapping the
notifications tab on slower devices (GrapheneOS).
This commit is contained in:
Barry Deen
2026-04-23 10:29:43 -04:00
parent f4c716551b
commit 503c46b256
@@ -22,6 +22,7 @@ import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
@@ -381,9 +382,9 @@ fun NotificationsScreen(
}
)
}
items(items = notifications, key = { it.id }, contentType = { "notification" }) { item ->
itemsIndexed(items = notifications, key = { _, it -> it.id }, contentType = { _, _ -> "notification" }) { index, item ->
val isExpanded = expandedId == item.id
val itemIndex = notifications.indexOf(item) + 1 // +1 for summary header
val itemIndex = index + 1 // +1 for summary header
val coroutineScope = rememberCoroutineScope()
ZenNotificationRow(
item = item,