[GH-ISSUE #2304] [Issue]: Streaming render storm — SplitMessageGroup defeats ConversationMessage memo, re-parsing the whole transcript ~22x/sec #1139

Closed
opened 2026-10-21 05:27:40 +07:00 by bsakaguchi · 1 comment
Owner

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

Originally assigned to: @Romuromylus on GitHub.

Summary

Severity: Medium — Performance. SplitMessageGroup rebuilds a fresh combined message object on every render and passes it as the message prop to ConversationMessage (a React.memo with the default shallow comparator). The new object reference always fails the memo, so during streaming — when the view re-renders ~22×/sec — every split assistant bubble in the mounted window re-runs its markdown parse/sanitize, even though only the streaming bubble's content actually changes.

Expected behavior

Non-streaming message bubbles should not re-render (and re-parse markdown) on every streaming buffer commit. Only the bubble whose content is actively changing should re-render.

Actual behavior

ConversationView subscribes to streamBuffer / thinkingBuffer (src/features/modes/conversation/components/ConversationView.tsx:408-409). The store commits the buffer every 45 ms (STREAM_BUFFER_COMMIT_INTERVAL_MS = 45, use-generate.ts:90) — ~22×/sec for the full duration of each generation — so ConversationView re-renders ~22×/sec.

ConversationMessage is memo() with the default shallow comparator (ConversationView.tsx:338, no custom comparator). SplitMessageGroup (ConversationView.tsx:1435) is an unmemoized plain function invoked inline in the render loop (1251). On every render it builds a new object literal:

const combinedContent = items.map((gi) => gi.msg.content).join("\n\n");
const combinedMsg = { ...firstItem.msg, content: combinedContent, extra: lastItem.msg.extra };
return (<ConversationMessage key={firstItem.key} message={combinedMsg} ... />);

The new combinedMsg reference fails the child memo, forcing a re-render. The re-render is genuinely costly: MessageContent (180) is unmemoized and calls renderMarkdownBlocks (a full line-by-line regex markdown→ReactNode parse, markdown.tsx:355) directly in its render body (214) with no useMemo; the renderedContent memo (484) only caches the macro-resolved string, not the markdown parse.

In Discord-style conversation mode, multi-paragraph assistant replies are split into __blockN groups (817-843), so most visible bubbles route through SplitMessageGroup. The mounted window holds up to 160 messages (MAX_MOUNTED_TRANSCRIPT_MESSAGES = 160), so the bulk of the transcript re-parses markdown ~22×/sec for the entire duration of every reply, scaling linearly with on-screen message count. The single-message path (1295-1318) passes the stable msg reference, so its memo correctly bails — confirming the split-group path is the leak.

Steps to reproduce

  1. Open a conversation-mode chat with several multi-line assistant messages already on screen.
  2. Send a message and let the assistant stream a reply.
  3. Profile renders: every SplitMessageGroup-rendered bubble in the window re-renders/re-parses ~22×/sec, not just the streaming one.

Impact area

  • Chat mode
  • Shared mode UI
  • Runtime systems: generation, world-state, visuals, tracker, or haptics

Environment

  • Branch or commit: refactor @ 47b16701
  • Run mode: Tauri desktop (same React frontend in server/web shell)
  • OS + version: not relevant (static source audit)
  • Node + pnpm versions: not relevant
  • Rust version, if relevant: not relevant
  • Remote Runtime URL configured? not relevant (applies to both)
  • Provider, model, or integration, if relevant: n/a

Logs, screenshots, or video

Static source audit; claims cited to file:line above.

Regression notes

Found via static audit of the refactor branch; not verified against main.

Additional context

Suggested fix: wrap SplitMessageGroup in React.memo and memoize combinedMsg / combinedContent with useMemo keyed on items (only recompute when item ids/content change); memoize MessageContent so the markdown parse only re-runs when content changes; and ideally gate streamBuffer / thinkingBuffer so non-streaming groups never receive live streaming props at all.

Template check

Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2304 Originally assigned to: @Romuromylus on GitHub. ## Summary **Severity: Medium — Performance.** `SplitMessageGroup` rebuilds a fresh combined message object on every render and passes it as the `message` prop to `ConversationMessage` (a `React.memo` with the default shallow comparator). The new object reference always fails the memo, so during streaming — when the view re-renders ~22×/sec — every split assistant bubble in the mounted window re-runs its markdown parse/sanitize, even though only the streaming bubble's content actually changes. ## Expected behavior Non-streaming message bubbles should not re-render (and re-parse markdown) on every streaming buffer commit. Only the bubble whose content is actively changing should re-render. ## Actual behavior `ConversationView` subscribes to `streamBuffer` / `thinkingBuffer` (`src/features/modes/conversation/components/ConversationView.tsx:408-409`). The store commits the buffer every 45 ms (`STREAM_BUFFER_COMMIT_INTERVAL_MS = 45`, `use-generate.ts:90`) — ~22×/sec for the full duration of each generation — so `ConversationView` re-renders ~22×/sec. `ConversationMessage` is `memo()` with the **default** shallow comparator (`ConversationView.tsx:338`, no custom comparator). `SplitMessageGroup` (`ConversationView.tsx:1435`) is an **unmemoized** plain function invoked inline in the render loop (`1251`). On every render it builds a new object literal: ```ts const combinedContent = items.map((gi) => gi.msg.content).join("\n\n"); const combinedMsg = { ...firstItem.msg, content: combinedContent, extra: lastItem.msg.extra }; return (<ConversationMessage key={firstItem.key} message={combinedMsg} ... />); ``` The new `combinedMsg` reference fails the child memo, forcing a re-render. The re-render is genuinely costly: `MessageContent` (`180`) is unmemoized and calls `renderMarkdownBlocks` (a full line-by-line regex markdown→ReactNode parse, `markdown.tsx:355`) directly in its render body (`214`) with no `useMemo`; the `renderedContent` memo (`484`) only caches the macro-resolved *string*, not the markdown parse. In Discord-style conversation mode, multi-paragraph assistant replies are split into `__blockN` groups (`817-843`), so most visible bubbles route through `SplitMessageGroup`. The mounted window holds up to 160 messages (`MAX_MOUNTED_TRANSCRIPT_MESSAGES = 160`), so the bulk of the transcript re-parses markdown ~22×/sec for the entire duration of every reply, scaling linearly with on-screen message count. The single-message path (`1295-1318`) passes the stable `msg` reference, so its memo correctly bails — confirming the split-group path is the leak. ## Steps to reproduce 1. Open a conversation-mode chat with several multi-line assistant messages already on screen. 2. Send a message and let the assistant stream a reply. 3. Profile renders: every `SplitMessageGroup`-rendered bubble in the window re-renders/re-parses ~22×/sec, not just the streaming one. ## Impact area - [x] Chat mode - [x] Shared mode UI - [x] Runtime systems: generation, world-state, visuals, tracker, or haptics ## Environment - Branch or commit: refactor @ 47b16701 - Run mode: Tauri desktop (same React frontend in server/web shell) - OS + version: not relevant (static source audit) - Node + pnpm versions: not relevant - Rust version, if relevant: not relevant - Remote Runtime URL configured? not relevant (applies to both) - Provider, model, or integration, if relevant: n/a ## Logs, screenshots, or video Static source audit; claims cited to file:line above. ## Regression notes Found via static audit of the refactor branch; not verified against main. ## Additional context Suggested fix: wrap `SplitMessageGroup` in `React.memo` and memoize `combinedMsg` / `combinedContent` with `useMemo` keyed on `items` (only recompute when item ids/content change); memoize `MessageContent` so the markdown parse only re-runs when content changes; and ideally gate `streamBuffer` / `thinkingBuffer` so non-streaming groups never receive live streaming props at all. ## Template check Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:27:40 +07:00
Author
Owner

@Romuromylus commented on GitHub (Jun 6, 2026):

Fixed by #2383, merged into refactor (squash 5781684d).

<!-- gh-comment-id:4637084891 --> @Romuromylus commented on GitHub (Jun 6, 2026): Fixed by #2383, merged into `refactor` (squash 5781684d).
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#1139
No description provided.