[PR #2539] [MERGED] fix(chat): memoize SplitMessageGroup to stop ~60x/sec re-renders during streaming #5641

Closed
opened 2026-10-22 04:18:04 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2539
Author: @Romuromylus
Created: 6/9/2026
Status: ✅ Merged
Merged: 6/9/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/split-message-group-memo


📝 Commits (3)

  • d35481d fix(chat): memoize SplitMessageGroup to stop ~60x/sec re-renders during streaming
  • 59843a5 fix(chat): add a memo comparator so non-regenerating split groups actually bail
  • d377cf7 Merge branch 'staging' into fix/split-message-group-memo

📊 Changes

1 file changed (+73 additions, -21 deletions)

View changed files

📝 packages/client/src/components/chat/ConversationView.tsx (+73 -21)

📄 Description

Linked issue

Closes #2531

Why this change

SplitMessageGroup was a plain, non-memoized function component, unlike its sibling ConversationMessage (which is memo-wrapped). ConversationView subscribes to the per-token streamBuffer/thinkingBuffer Zustand slices, and the typewriter loop in use-generate.ts updates streamBuffer once per requestAnimationFrame (~60×/sec) during every generation. The single render site passed both buffers to every mounted SplitMessageGroup (up to 160), so all split groups received changing props each frame and re-executed their body (recomputing fullContent = items.map(...).join("\n")) for the whole duration of streaming — even though only the regenerating group actually consumes the buffers. The inner ConversationMessage children still memo-bail, so this is a Low-severity render cleanup (parent-body work + reconciliation), not a correctness bug.

What changed

packages/client/src/components/chat/ConversationView.tsx:

  • Added the named memo import and wrapped SplitMessageGroup in memo() (mirroring ConversationMessage.tsx:332).
  • At the render site, compute isRegenGroup = regenerateMessageId === groupItems[0].msg.id and pass live streamBuffer/thinkingBuffer only to that group; every other group gets "", so its props are byte-stable across the ~60 updates/sec and the memo() bails.

The regenerating group still receives live buffers and streams token-by-token. The non-regen branches never referenced the buffers, so passing "" is behavior-preserving. items (groupItems) is still rebuilt each parent render, so in the worst case memo re-renders by reference — meaning the payoff is the issue's stated modest gain (matching Low severity), never a correctness risk; the change only ever removes prop churn.

Not a regression: byte-identical on main; shared-engine render characteristic.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

pnpm check passes locally (type-checks the memo() wrapper + the new isRegenGroup const, lints unused-import/exhaustive-deps). There is no client test suite, so pnpm check plus the live observation below is the canonical proof.

Still to verify manually against the deploy (React DevTools Profiler):

  • Open a chat with several multi-line assistant messages, send a message, let it stream. After the fix only the streaming/regenerating SplitMessageGroup re-renders ~60×/sec; every other mounted split group renders 0 extra times.
  • Negative controls: the streaming group still types out token-by-token; regenerating (swipe/retry) an existing assistant message still streams that group live; a non-regenerating multi-line message's rendered text is identical before/during/after the stream; edit and delete on a split group still work.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/2539 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 6/9/2026 **Status:** ✅ Merged **Merged:** 6/9/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/split-message-group-memo` --- ### 📝 Commits (3) - [`d35481d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d35481dde239b1adfe4e80532fdc5d6ad92cd8e8) fix(chat): memoize SplitMessageGroup to stop ~60x/sec re-renders during streaming - [`59843a5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/59843a505adca9b24ce9a4ad299c9e3bf97c42f7) fix(chat): add a memo comparator so non-regenerating split groups actually bail - [`d377cf7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d377cf7f5c815fbcdca2c74db66236acc19d2160) Merge branch 'staging' into fix/split-message-group-memo ### 📊 Changes **1 file changed** (+73 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ConversationView.tsx` (+73 -21) </details> ### 📄 Description ## Linked issue Closes #2531 ## Why this change `SplitMessageGroup` was a plain, non-memoized function component, unlike its sibling `ConversationMessage` (which is `memo`-wrapped). `ConversationView` subscribes to the per-token `streamBuffer`/`thinkingBuffer` Zustand slices, and the typewriter loop in `use-generate.ts` updates `streamBuffer` once per `requestAnimationFrame` (~60×/sec) during every generation. The single render site passed both buffers to **every** mounted `SplitMessageGroup` (up to 160), so all split groups received changing props each frame and re-executed their body (recomputing `fullContent = items.map(...).join("\n")`) for the whole duration of streaming — even though only the regenerating group actually consumes the buffers. The inner `ConversationMessage` children still memo-bail, so this is a Low-severity render cleanup (parent-body work + reconciliation), not a correctness bug. ## What changed `packages/client/src/components/chat/ConversationView.tsx`: - Added the named `memo` import and wrapped `SplitMessageGroup` in `memo()` (mirroring `ConversationMessage.tsx:332`). - At the render site, compute `isRegenGroup = regenerateMessageId === groupItems[0].msg.id` and pass live `streamBuffer`/`thinkingBuffer` only to that group; every other group gets `""`, so its props are byte-stable across the ~60 updates/sec and the `memo()` bails. The regenerating group still receives live buffers and streams token-by-token. The non-regen branches never referenced the buffers, so passing `""` is behavior-preserving. `items` (`groupItems`) is still rebuilt each parent render, so in the worst case `memo` re-renders by reference — meaning the payoff is the issue's stated modest gain (matching Low severity), never a correctness risk; the change only ever removes prop churn. Not a regression: byte-identical on `main`; shared-engine render characteristic. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes `pnpm check` passes locally (type-checks the `memo()` wrapper + the new `isRegenGroup` const, lints unused-import/exhaustive-deps). There is no client test suite, so `pnpm check` plus the live observation below is the canonical proof. Still to verify manually against the deploy (React DevTools Profiler): - Open a chat with several multi-line assistant messages, send a message, let it stream. After the fix only the streaming/regenerating `SplitMessageGroup` re-renders ~60×/sec; every other mounted split group renders 0 extra times. - Negative controls: the streaming group still types out token-by-token; regenerating (swipe/retry) an existing assistant message still streams that group live; a non-regenerating multi-line message's rendered text is identical before/during/after the stream; edit and delete on a split group still work. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:18: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#5641
No description provided.