diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..40a6681 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-05-24 - Compose LazyColumn Performance +**Learning:** Found multiple instances of `LazyColumn` in `AiAssistantBottomSheet.kt` iterating over lists without providing a `key`. This causes unnecessary recompositions of all list items in Jetpack Compose when the underlying dataset changes (e.g., chat messages update). +**Action:** Added stable `key` identifiers to `items(chatMessages)`, `items(filteredHistory)`, and `items(allNotes)` to allow Jetpack Compose to efficiently track changes and avoid full list re-renders. Ensure `key` parameters are used for all dynamic lists in the future. diff --git a/app/src/main/java/com/astralquarks/notes/ui/components/AiAssistantBottomSheet.kt b/app/src/main/java/com/astralquarks/notes/ui/components/AiAssistantBottomSheet.kt index f50a192..2e12d27 100644 --- a/app/src/main/java/com/astralquarks/notes/ui/components/AiAssistantBottomSheet.kt +++ b/app/src/main/java/com/astralquarks/notes/ui/components/AiAssistantBottomSheet.kt @@ -713,7 +713,7 @@ fun AiAssistantBottomSheet( } } - items(chatMessages) { msg -> + items(chatMessages, key = { msg -> "${msg.timestamp}_${msg.role}" }) { msg -> val isUser = msg.role == "user" val parsed = remember(msg.content) { if (!isUser) GeminiActionParser.parse(msg.content) else ParsedAiMessage(msg.content, null) @@ -1138,7 +1138,7 @@ fun AiAssistantBottomSheet( .weight(1f), verticalArrangement = Arrangement.spacedBy(10.dp) ) { - items(filteredHistory) { item -> + items(filteredHistory, key = { item -> item.id }) { item -> Card( shape = RoundedCornerShape(16.dp), colors = CardDefaults.cardColors( @@ -1368,7 +1368,7 @@ fun AiAssistantBottomSheet( ) LazyColumn(verticalArrangement = Arrangement.spacedBy(4.dp)) { - items(allNotes) { n -> + items(allNotes, key = { n -> n.id }) { n -> val isTargeted = targetedNoteIds.contains(n.id) Surface( shape = RoundedCornerShape(12.dp),