From 4fc4d097ccb196570fe57206f9a1a6b060912b7f Mon Sep 17 00:00:00 2001 From: m57 <41645758+Hy4ri@users.noreply.github.com> Date: Mon, 28 Sep 2026 00:49:09 +0300 Subject: [PATCH] perf(chat): memoize streaming typing-effect text (#1315) (#1345) --- .../ui/chat/fullbleed/FullBleedStreaming.kt | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/m57/hermescontrol/ui/chat/fullbleed/FullBleedStreaming.kt b/app/src/main/java/com/m57/hermescontrol/ui/chat/fullbleed/FullBleedStreaming.kt index 5733834b..572ccb89 100644 --- a/app/src/main/java/com/m57/hermescontrol/ui/chat/fullbleed/FullBleedStreaming.kt +++ b/app/src/main/java/com/m57/hermescontrol/ui/chat/fullbleed/FullBleedStreaming.kt @@ -71,19 +71,31 @@ internal fun StreamingFullBleedWithTypingEffect( } // Derive display text from the latest full content at each recomposition - val words = streaming.content.split(" ") + val words = remember(streaming.content) { streaming.content.split(" ") } val visibleCount = if (visibleWordCount >= Int.MAX_VALUE / 2) { words.size } else { visibleWordCount.coerceIn(0, words.size) } + val isStreaming = currentIsStreaming.value val displayText = - words.take(visibleCount.coerceAtLeast(1)).joinToString(" ") + - if (caretVisible && currentIsStreaming.value) "▍" else "" + remember(words, visibleCount, caretVisible, isStreaming) { + words.take(visibleCount.coerceAtLeast(1)).joinToString(" ") + + if (caretVisible && isStreaming) "▍" else "" + } + + val displayMessage = + remember(streaming, displayText) { + if (streaming.content == displayText) { + streaming + } else { + streaming.copy(content = displayText) + } + } FullBleedAgentMessage( - message = streaming.copy(content = displayText), + message = displayMessage, showReasoning = showReasoning, searchQuery = "", isCurrentMatch = false,