[PR #2383] [MERGED] Memoize conversation message rendering to stop the streaming re-parse storm #5571

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

📋 Pull Request Information

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

Base: refactor ← Head: fix/streaming-render-storm


📝 Commits (2)

  • 2ad2b7c Memoize conversation message rendering to stop the streaming re-parse storm
  • 73a2dbd Memoize the combined split-message object to cut streaming re-renders

📊 Changes

3 files changed (+112 additions, -25 deletions)

View changed files

📝 src/features/modes/conversation/components/ConversationMessage.tsx (+28 -16)
📝 src/features/modes/conversation/components/ConversationView.tsx (+21 -9)
➕ src/features/modes/conversation/components/MessageContent.test.tsx (+63 -0)

📄 Description

Linked issue

Closes #2304

Why this change

While a message generates, ConversationView re-renders on every ~45ms stream-buffer commit (~22x/sec). MessageContent ran renderMarkdownBlocks directly in its render body and was not memoized, so every mounted message (up to the full render window) re-parsed its entire markdown on each commit — the streaming render storm.

What changed

  • Wrap MessageContent in React.memo and compute the parsed output in a useMemo keyed on content / mentionNames, so renderMarkdownBlocks only re-runs for a message whose content actually changed.
  • Stabilize the onImageOpen callback (useCallback) so the memo can bail.
  • The useMemo runs unconditionally before the image-URL early return, keeping the Rules of Hooks intact.

Refactor impact

Primary owner: chat / conversation mode UI (src/features/modes/conversation/components/ConversationMessage.tsx)

Impact areas reviewed:

  • MessageContent is conversation-mode-scoped; renderedContent (macro-resolved string) and mentionNames are already memoized upstream, so the memo bails for unchanged messages during streaming.

Boundary notes:

  • none — no cross-layer imports; pure render optimization.

Pressure points touched:

  • none

Validation

  • Matching validation command passes locally
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • pnpm vitest run src/features/modes/conversation/components/MessageContent.test.tsx — 3 passed (no re-parse on unchanged content across re-renders with a new onImageOpen identity; re-parse on content change; image URL bypasses parse).
  • pnpm exec tsc -b — clean. pnpm exec eslint on the touched files — clean.

Feature Discoverability

  • N/A because this PR is a performance bugfix and does not add a new thing users need to find.

Reason:

  • Render optimization only.

Docs and release impact

  • No docs changes needed

🔄 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/2383 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 6/5/2026 **Status:** ✅ Merged **Merged:** 6/6/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `refactor` ← **Head:** `fix/streaming-render-storm` --- ### 📝 Commits (2) - [`2ad2b7c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2ad2b7cfccf67d3bfea3fe918ca7fef1b67ff211) Memoize conversation message rendering to stop the streaming re-parse storm - [`73a2dbd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/73a2dbdf10d8cf70165d72939464a42c81b94c6c) Memoize the combined split-message object to cut streaming re-renders ### 📊 Changes **3 files changed** (+112 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `src/features/modes/conversation/components/ConversationMessage.tsx` (+28 -16) 📝 `src/features/modes/conversation/components/ConversationView.tsx` (+21 -9) ➕ `src/features/modes/conversation/components/MessageContent.test.tsx` (+63 -0) </details> ### 📄 Description ## Linked issue Closes #2304 ## Why this change While a message generates, `ConversationView` re-renders on every ~45ms stream-buffer commit (~22x/sec). `MessageContent` ran `renderMarkdownBlocks` directly in its render body and was not memoized, so every mounted message (up to the full render window) re-parsed its entire markdown on each commit — the streaming render storm. ## What changed - Wrap `MessageContent` in `React.memo` and compute the parsed output in a `useMemo` keyed on `content` / `mentionNames`, so `renderMarkdownBlocks` only re-runs for a message whose content actually changed. - Stabilize the `onImageOpen` callback (`useCallback`) so the memo can bail. - The `useMemo` runs unconditionally before the image-URL early return, keeping the Rules of Hooks intact. ## Refactor impact Primary owner: chat / conversation mode UI (`src/features/modes/conversation/components/ConversationMessage.tsx`) Impact areas reviewed: - `MessageContent` is conversation-mode-scoped; `renderedContent` (macro-resolved string) and `mentionNames` are already memoized upstream, so the memo bails for unchanged messages during streaming. Boundary notes: - none — no cross-layer imports; pure render optimization. Pressure points touched: - none ## Validation - [ ] Matching validation command passes locally - [ ] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - `pnpm vitest run src/features/modes/conversation/components/MessageContent.test.tsx` — 3 passed (no re-parse on unchanged content across re-renders with a new `onImageOpen` identity; re-parse on content change; image URL bypasses parse). - `pnpm exec tsc -b` — clean. `pnpm exec eslint` on the touched files — clean. ## Feature Discoverability - [x] N/A because this PR is a performance bugfix and does not add a new thing users need to find. Reason: - Render optimization only. ## Docs and release impact - [x] No docs changes needed --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:17:29 +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#5571
No description provided.