[GH-ISSUE #4659] Roleplay streaming replaces its text node every frame, causing Firefox render churn #2552

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Roleplay responses can stream slightly less smoothly in Firefox. Profiling points to the lightweight live-stream renderer replacing the complete text child on every animation-frame update through element.textContent = next.

This path was introduced in commit 40206d1da to avoid rebuilding ChatMessage through React for every character. It succeeds at bypassing React, but assigning textContent removes and recreates the underlying Text node, which causes repeated accessibility, style, layout, and paint work.

Expected behavior

Roleplay output should reveal at a steady frame-paced cadence without replacing DOM children, repeatedly rebuilding the Firefox accessibility subtree, or forcing avoidable layout work.

Actual behavior

An 8.9-second Firefox profile recorded during Roleplay streaming showed:

  • 1,067 text-removal and 1,066 text-insertion accessibility events.
  • 3,295 accessibility subtree prune/insert operations.
  • 3,483 image-paint events.
  • Approximately 7.5 seconds of content-main-thread CPU and 7.2 seconds of renderer CPU.
  • A peak event delay of approximately 765 ms.

Firefox Inspector and its Compatibility panel were open during the capture. They amplified the problem by reacting to each child replacement: the profile contains 1,167 DOM-walker child queries and 1,167 CSS compatibility scans, with approximately 1.94 seconds of sampled main-thread CPU inside getNodeCssIssues. The capture also used a React development build, so the absolute timings are not representative of production, but the repeated node replacement is visible independently of that overhead.

A separate state update during the capture rerendered the complete mounted transcript: 60 ChatMessage components and 493 action buttons in approximately 375 ms. Streaming auto-follow also reads scrollHeight and calls scrollTo at animation-frame cadence, adding layout pressure while the text grows.

Steps to reproduce

  1. Run Marinara Engine in Firefox.
  2. Open a Roleplay chat with a substantial mounted transcript.
  3. Start a streamed response while the transcript is pinned near the bottom.
  4. Record the content process with the Firefox Profiler.
  5. Inspect accessibility text events, DOM mutations, layout, and paint work while the response grows.
  6. Optionally open Firefox Inspector and the Compatibility panel to make the mutation amplification especially visible.

Environment

  • Marinara Engine version: 2.4.2 / current staging
  • Install type: source development build
  • OS + version: macOS 26.5.2
  • Browser or app shell: Firefox 153.0, build 20260803132010

Logs, screenshots, or video

The profile used a 1 ms sampling interval and covered approximately 8.9 seconds of active Roleplay streaming. The relevant implementation is RoleplayLiveStreamText in packages/client/src/components/chat/ChatRoleplaySurface.tsx.

Related secondary paths:

  • Per-frame bottom-follow measurement in packages/client/src/components/chat/ChatArea.tsx.
  • Transcript-wide mutation observation in packages/client/src/components/chat/ChatArea.tsx.
  • Echo Chamber auto-scroll layout measurement in packages/client/src/components/chat/EchoChamberPanel.tsx.

Additional context

A small initial fix should retain one Text node for the lifetime of the live row and update its .data, or append only the new suffix with appendData, rather than assigning textContent to the parent span on every frame. Full-buffer rewrites, regeneration resets, and chat switching still need to replace the text data correctly.

After that change, re-profile a production build with Firefox Inspector closed. If a visible hitch remains, separately isolate transcript-wide rerenders and coalesce stream auto-scroll measurement and writing to one operation per frame.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @SpicyMarinara on GitHub (Aug 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4659 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Roleplay responses can stream slightly less smoothly in Firefox. Profiling points to the lightweight live-stream renderer replacing the complete text child on every animation-frame update through `element.textContent = next`. This path was introduced in commit 40206d1da to avoid rebuilding `ChatMessage` through React for every character. It succeeds at bypassing React, but assigning `textContent` removes and recreates the underlying `Text` node, which causes repeated accessibility, style, layout, and paint work. ## Expected behavior Roleplay output should reveal at a steady frame-paced cadence without replacing DOM children, repeatedly rebuilding the Firefox accessibility subtree, or forcing avoidable layout work. ## Actual behavior An 8.9-second Firefox profile recorded during Roleplay streaming showed: - 1,067 text-removal and 1,066 text-insertion accessibility events. - 3,295 accessibility subtree prune/insert operations. - 3,483 image-paint events. - Approximately 7.5 seconds of content-main-thread CPU and 7.2 seconds of renderer CPU. - A peak event delay of approximately 765 ms. Firefox Inspector and its Compatibility panel were open during the capture. They amplified the problem by reacting to each child replacement: the profile contains 1,167 DOM-walker child queries and 1,167 CSS compatibility scans, with approximately 1.94 seconds of sampled main-thread CPU inside `getNodeCssIssues`. The capture also used a React development build, so the absolute timings are not representative of production, but the repeated node replacement is visible independently of that overhead. A separate state update during the capture rerendered the complete mounted transcript: 60 `ChatMessage` components and 493 action buttons in approximately 375 ms. Streaming auto-follow also reads `scrollHeight` and calls `scrollTo` at animation-frame cadence, adding layout pressure while the text grows. ## Steps to reproduce 1. Run Marinara Engine in Firefox. 2. Open a Roleplay chat with a substantial mounted transcript. 3. Start a streamed response while the transcript is pinned near the bottom. 4. Record the content process with the Firefox Profiler. 5. Inspect accessibility text events, DOM mutations, layout, and paint work while the response grows. 6. Optionally open Firefox Inspector and the Compatibility panel to make the mutation amplification especially visible. ## Environment - Marinara Engine version: 2.4.2 / current `staging` - Install type: source development build - OS + version: macOS 26.5.2 - Browser or app shell: Firefox 153.0, build 20260803132010 ## Logs, screenshots, or video The profile used a 1 ms sampling interval and covered approximately 8.9 seconds of active Roleplay streaming. The relevant implementation is `RoleplayLiveStreamText` in `packages/client/src/components/chat/ChatRoleplaySurface.tsx`. Related secondary paths: - Per-frame bottom-follow measurement in `packages/client/src/components/chat/ChatArea.tsx`. - Transcript-wide mutation observation in `packages/client/src/components/chat/ChatArea.tsx`. - Echo Chamber auto-scroll layout measurement in `packages/client/src/components/chat/EchoChamberPanel.tsx`. ## Additional context A small initial fix should retain one `Text` node for the lifetime of the live row and update its `.data`, or append only the new suffix with `appendData`, rather than assigning `textContent` to the parent span on every frame. Full-buffer rewrites, regeneration resets, and chat switching still need to replace the text data correctly. After that change, re-profile a production build with Firefox Inspector closed. If a visible hitch remains, separately isolate transcript-wide rerenders and coalesce stream auto-scroll measurement and writing to one operation per frame. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:50:00 +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#2552
No description provided.