[GH-ISSUE #2531] [Issue]: SplitMessageGroup is not memoized — re-renders ~60x/sec during streaming #1258

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

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

Originally assigned to: @Romuromylus on GitHub.

Summary

Severity: Low — performance (client render). SplitMessageGroup is not memoized but receives the per-token streamBuffer/thinkingBuffer props, so every split assistant message currently mounted re-runs its function body ~60×/sec for the full duration of every generation. The sibling renderer ConversationMessage is already memo-wrapped and bails out correctly.

Expected behavior

SplitMessageGroup should be wrapped in React.memo (like ConversationMessage) and only receive the streaming buffers when it is actually the regenerating group, so non-regenerating groups have stable props and skip re-render during streaming.

Actual behavior

packages/client/src/components/chat/ConversationView.tsx:1195 defines SplitMessageGroup as a plain function component with no memo, and the render site (:1018-1024) hands it streamBuffer={streamBuffer} and thinkingBuffer={thinkingBuffer}:

function SplitMessageGroup(/* ... */) { /* not memo-wrapped */ }
// render site:
<SplitMessageGroup
  // ...
  streamBuffer={streamBuffer}
  thinkingBuffer={thinkingBuffer}
/>

ConversationView subscribes to streamBuffer/thinkingBuffer (:351-352), and the typewriter loop calls setStreamBuffer once per requestAnimationFrame (use-generate.ts:888/903) → ~60 updates/sec during streaming. Every mounted SplitMessageGroup (up to MAX_MOUNTED_TRANSCRIPT_MESSAGES = 160; multi-line assistant replies are split into groups very commonly in roleplay) re-executes its body each frame (recomputing fullContent = items.map(gi => gi.msg.content).join("\n") at :1233) even though only the regenerating group uses those buffers (the isRegen branch, :1316-1379). The inner ConversationMessage children still memo-bail, so this is bounded per-frame parent-body work + reconciliation, not a full subtree re-parse — hence Low.

Steps to reproduce

  1. Open a chat whose visible transcript has several multi-line assistant messages (each becomes a SplitMessageGroup).
  2. Send a message and let the reply stream.
  3. While streaming, ConversationView re-renders ~60×/sec and every SplitMessageGroup re-executes its body each frame because it is not memoized and its streamBuffer/thinkingBuffer props change every token.

Environment

  • Marinara Engine version: 1.6.1 (staging @ a9fdae8)
  • Install type: source
  • OS + version: n/a — static source audit
  • Browser or app shell: n/a

Logs, screenshots, or video

Static source audit, cited to file:line above.

Additional context

Fix: wrap SplitMessageGroup in React.memo (mirroring ConversationMessage.tsx:332). To make the memo effective, only feed streamBuffer/thinkingBuffer to a SplitMessageGroup when it is the regenerating group (regenerateMessageId === items[0].msg.id); pass empty strings / omit otherwise so non-regenerating groups have stable props and bail. The isRegen branch (:1316-1379) is the only place those buffers are used.

The payoff is modest because the inner children already memo-bail — filing as a low-priority render cleanup.

Regression notes: found via static audit; main (65a0395) has the byte-identical structure (SplitMessageGroup a plain function fed streamBuffer, ConversationMessage memoized), so this is a shared pre-existing pattern, not a main→staging regression.

Template check

Please uncheck (untick) 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 9, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2531 Originally assigned to: @Romuromylus on GitHub. ## Summary **Severity: Low — performance (client render).** `SplitMessageGroup` is not memoized but receives the per-token `streamBuffer`/`thinkingBuffer` props, so every split assistant message currently mounted re-runs its function body ~60×/sec for the full duration of every generation. The sibling renderer `ConversationMessage` is already `memo`-wrapped and bails out correctly. ## Expected behavior `SplitMessageGroup` should be wrapped in `React.memo` (like `ConversationMessage`) and only receive the streaming buffers when it is actually the regenerating group, so non-regenerating groups have stable props and skip re-render during streaming. ## Actual behavior `packages/client/src/components/chat/ConversationView.tsx:1195` defines `SplitMessageGroup` as a plain function component with no `memo`, and the render site (`:1018-1024`) hands it `streamBuffer={streamBuffer}` and `thinkingBuffer={thinkingBuffer}`: ```tsx function SplitMessageGroup(/* ... */) { /* not memo-wrapped */ } // render site: <SplitMessageGroup // ... streamBuffer={streamBuffer} thinkingBuffer={thinkingBuffer} /> ``` `ConversationView` subscribes to `streamBuffer`/`thinkingBuffer` (`:351-352`), and the typewriter loop calls `setStreamBuffer` once per `requestAnimationFrame` (`use-generate.ts:888/903`) → ~60 updates/sec during streaming. Every mounted `SplitMessageGroup` (up to `MAX_MOUNTED_TRANSCRIPT_MESSAGES = 160`; multi-line assistant replies are split into groups very commonly in roleplay) re-executes its body each frame (recomputing `fullContent = items.map(gi => gi.msg.content).join("\n")` at `:1233`) even though only the regenerating group uses those buffers (the `isRegen` branch, `:1316-1379`). The inner `ConversationMessage` children still memo-bail, so this is bounded per-frame parent-body work + reconciliation, not a full subtree re-parse — hence Low. ## Steps to reproduce 1. Open a chat whose visible transcript has several multi-line assistant messages (each becomes a `SplitMessageGroup`). 2. Send a message and let the reply stream. 3. While streaming, `ConversationView` re-renders ~60×/sec and every `SplitMessageGroup` re-executes its body each frame because it is not memoized and its `streamBuffer`/`thinkingBuffer` props change every token. ## Environment - Marinara Engine version: 1.6.1 (`staging @ a9fdae8`) - Install type: source - OS + version: n/a — static source audit - Browser or app shell: n/a ## Logs, screenshots, or video Static source audit, cited to file:line above. ## Additional context Fix: wrap `SplitMessageGroup` in `React.memo` (mirroring `ConversationMessage.tsx:332`). To make the memo effective, only feed `streamBuffer`/`thinkingBuffer` to a `SplitMessageGroup` when it is the regenerating group (`regenerateMessageId === items[0].msg.id`); pass empty strings / omit otherwise so non-regenerating groups have stable props and bail. The `isRegen` branch (`:1316-1379`) is the only place those buffers are used. The payoff is modest because the inner children already memo-bail — filing as a low-priority render cleanup. Regression notes: found via static audit; `main` (`65a0395`) has the byte-identical structure (`SplitMessageGroup` a plain function fed `streamBuffer`, `ConversationMessage` memoized), so this is a shared pre-existing pattern, not a `main`→`staging` regression. ## Template check Please **uncheck (untick)** 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:30:04 +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#1258
No description provided.