[GH-ISSUE #3223] Conversation mode: whole transcript re-renders every streaming frame (unmemoized emoji/sticker maps defeat message memo) #1733

Closed
opened 2026-10-21 05:42:07 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @kolacheee on GitHub (Jul 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3223

Originally assigned to: @SpicyMarinara, @kolacheee on GitHub.

What happens

In conversation mode, every mounted message re-renders on every frame of a streaming reply (React DevTools "highlight updates" shows the whole transcript flashing per token frame). On long chats (100+ mounted messages, group chats with multi-speaker replies) this costs roughly 15–35ms per frame on a desktop — visible stutter during generation, worse on laptops or when a local model is saturating the same CPU.

Try it yourself

  1. Conversation chat with a long history (scroll up so 80+ messages are mounted); custom emojis/stickers don't need to be configured — the bug is unconditional.
  2. Open React DevTools → Components → enable "Highlight updates when components render".
  3. Send a message. While tokens stream in, every message in the transcript flashes on every frame, not just the streaming one.

Why it happens

useConversationCustomEmojis() and useConversationCustomStickers() (packages/client/src/hooks/use-conversation-custom-emojis.ts / use-conversation-custom-stickers.ts) build a fresh list array and a fresh Map on every render — there's no memoization, and the useQueries inputs churn identity per render anyway. ConversationView passes those Maps as emojiMap/stickerMap props to every memo(ConversationMessage), so the memo's shallow compare fails for all mounted messages on every ConversationView render — and ConversationView renders once per animation frame during any token stream. This is the same class as #3164/#3104 ("cheap per-message work × every mounted message × every render"): each message then re-runs its markdown/custom-emoji/mention pipeline per segment plus (since #3211) its per-segment reaction-button subtrees, measured at ~3.3ms of pure element work per pass for 100 messages × 4 segments before reconciliation.

ChatArea already fixed the identical disease for chatCharacterRows in #3166 with a ref-backed element-wise reuse (ChatArea.tsx ~750) — these two hooks are the remaining identity-breakers on the ConversationMessage prop surface (characterMap, personaInfo and the callbacks are already stable).

Suggested fix

Apply the same row-stability pattern inside both hooks: compare the freshly-built list element-wise against a ref-cached previous one (all fields are primitives) and return the cached { list, map } object when unchanged.

Found by a regression/perf sweep of the reaction PRs (#3211/#3221) — the bug predates them, but per-segment reactions multiplied the work living under the broken memo boundary.

Originally created by @kolacheee on GitHub (Jul 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3223 Originally assigned to: @SpicyMarinara, @kolacheee on GitHub. **What happens** In conversation mode, every mounted message re-renders on every frame of a streaming reply (React DevTools "highlight updates" shows the whole transcript flashing per token frame). On long chats (100+ mounted messages, group chats with multi-speaker replies) this costs roughly 15–35ms per frame on a desktop — visible stutter during generation, worse on laptops or when a local model is saturating the same CPU. **Try it yourself** 1. Conversation chat with a long history (scroll up so 80+ messages are mounted); custom emojis/stickers don't need to be configured — the bug is unconditional. 2. Open React DevTools → Components → enable "Highlight updates when components render". 3. Send a message. While tokens stream in, every message in the transcript flashes on every frame, not just the streaming one. **Why it happens** `useConversationCustomEmojis()` and `useConversationCustomStickers()` (`packages/client/src/hooks/use-conversation-custom-emojis.ts` / `use-conversation-custom-stickers.ts`) build a fresh `list` array and a fresh `Map` on every render — there's no memoization, and the `useQueries` inputs churn identity per render anyway. `ConversationView` passes those Maps as `emojiMap`/`stickerMap` props to every `memo(ConversationMessage)`, so the memo's shallow compare fails for all mounted messages on every `ConversationView` render — and ConversationView renders once per animation frame during any token stream. This is the same class as #3164/#3104 ("cheap per-message work × every mounted message × every render"): each message then re-runs its markdown/custom-emoji/mention pipeline per segment plus (since #3211) its per-segment reaction-button subtrees, measured at ~3.3ms of pure element work per pass for 100 messages × 4 segments before reconciliation. `ChatArea` already fixed the identical disease for `chatCharacterRows` in #3166 with a ref-backed element-wise reuse (ChatArea.tsx ~750) — these two hooks are the remaining identity-breakers on the ConversationMessage prop surface (characterMap, personaInfo and the callbacks are already stable). **Suggested fix** Apply the same row-stability pattern inside both hooks: compare the freshly-built list element-wise against a ref-cached previous one (all fields are primitives) and return the cached `{ list, map }` object when unchanged. *Found by a regression/perf sweep of the reaction PRs (#3211/#3221) — the bug predates them, but per-segment reactions multiplied the work living under the broken memo boundary.*
bsakaguchi 2026-10-21 05:42:07 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1733
No description provided.