[GH-ISSUE #4628] [Issue]: Professor Mari streaming has no render throttling — per-token full re-render + full markdown re-parse (O(n²), mobile heat/battery) #2529

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The Professor Mari assistant streams with no render throttling: every SSE token event triggers an immediate state update that re-renders the entire home chat component, and the growing reply's markdown is fully re-parsed on each of those renders — O(reply-length²) work at token rate for the whole generation. The main chat path was given exactly this fix for #2878 (useThrottledStreamBuffer); the Mari path never got it. Reported by two mobile users as phone heat/battery drain that is "worse with the assistant", especially on slow models (long streams).

Expected behavior

Mari streaming coalesces token updates (once per animation frame, like the main chat's useThrottledStreamBuffer, added for #2878) and does not re-parse the full transcript markdown on every token.

Actual behavior

  • Every SSE token event calls setWorkspaceTimeline((current) => appendTextTimeline(current, event.data)) immediately (packages/client/src/components/chat/HomeProfessorMariChat.tsx:3385-3392) — no rafThrottle / buffer anywhere in the file.
  • The component (~4,400 lines) contains zero React.memo, so every timeline item and history message re-renders per token.
  • CompactMarkdown (HomeProfessorMariChat.tsx:1149-1160) calls renderMarkdownBlocks() (packages/client/src/lib/markdown.tsx:404 — a recursive regex parse) inline in the render body with no memoization, over the full accumulated text, on every render.

Net cost per token is O(current transcript length); over a generation it is quadratic in reply length. On a slow model this is minutes of sustained CPU on the client — matching the user reports (phone warm, "worse with the marinara helper", worse with slow models).

Steps to reproduce

  1. On a phone (or with DevTools CPU throttling), open the Home screen and ask Professor Mari something that produces a long reply on a slow connection/model.
  2. Observe sustained CPU/heat for the entire stream; profiler shows per-token full component render + markdown re-parse of the growing reply.
  3. Compare with a normal conversation chat, which coalesces via useThrottledStreamBuffer (packages/client/src/hooks/use-throttled-stream-buffer.ts:9-26, cited to #2878) — same stream, far less render work.

Environment

  • Marinara Engine version: 2.4.2 (staging, 93738d9b1)
  • Install type: source
  • OS + version: reported on Android (browser client + Termux); reproducible on any platform with CPU profiling
  • Browser or app shell: mobile browsers

Logs, screenshots, or video

Verified by code trace (three independent verification passes). Key contrast: ConversationView.tsx:338 uses useThrottledStreamBuffer(); HomeProfessorMariChat.tsx has no throttling import at all.

Additional context

This is effectively a regression-by-omission of the #2878 fix class — which also matches the reporters' sense that battery drain is back "again". Suggested fix, mirroring the existing pattern: (a) accumulate token/thinking deltas in a ref and flush setWorkspaceTimeline via the existing rafThrottle util (packages/client/src/lib/raf-throttle.ts), delivering non-growth transitions (first token, tool/status events, clear) synchronously; (b) memoize CompactMarkdown's parse (useMemo on the input text) and React.memo the timeline/history items so only the streaming entry re-renders. No behavior change, purely render-cost.

Filed alongside #4629 (extension runtime polling) and #4630 (Noodler reconcile scans) from the same mobile-battery investigation.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Aug 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4628 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The Professor Mari assistant streams with **no render throttling**: every SSE token event triggers an immediate state update that re-renders the entire home chat component, and the growing reply's markdown is fully re-parsed on each of those renders — O(reply-length²) work at token rate for the whole generation. The main chat path was given exactly this fix for #2878 (`useThrottledStreamBuffer`); the Mari path never got it. Reported by two mobile users as phone heat/battery drain that is "worse with the assistant", especially on slow models (long streams). ## Expected behavior Mari streaming coalesces token updates (once per animation frame, like the main chat's `useThrottledStreamBuffer`, added for #2878) and does not re-parse the full transcript markdown on every token. ## Actual behavior - Every SSE `token` event calls `setWorkspaceTimeline((current) => appendTextTimeline(current, event.data))` immediately (`packages/client/src/components/chat/HomeProfessorMariChat.tsx:3385-3392`) — no rafThrottle / buffer anywhere in the file. - The component (~4,400 lines) contains **zero `React.memo`**, so every timeline item and history message re-renders per token. - `CompactMarkdown` (`HomeProfessorMariChat.tsx:1149-1160`) calls `renderMarkdownBlocks()` (`packages/client/src/lib/markdown.tsx:404` — a recursive regex parse) inline in the render body with no memoization, over the full accumulated text, on every render. Net cost per token is O(current transcript length); over a generation it is quadratic in reply length. On a slow model this is **minutes of sustained CPU on the client** — matching the user reports (phone warm, "worse with the marinara helper", worse with slow models). ## Steps to reproduce 1. On a phone (or with DevTools CPU throttling), open the Home screen and ask Professor Mari something that produces a long reply on a slow connection/model. 2. Observe sustained CPU/heat for the entire stream; profiler shows per-token full component render + markdown re-parse of the growing reply. 3. Compare with a normal conversation chat, which coalesces via `useThrottledStreamBuffer` (`packages/client/src/hooks/use-throttled-stream-buffer.ts:9-26`, cited to #2878) — same stream, far less render work. ## Environment - Marinara Engine version: 2.4.2 (staging, 93738d9b1) - Install type: source - OS + version: reported on Android (browser client + Termux); reproducible on any platform with CPU profiling - Browser or app shell: mobile browsers ## Logs, screenshots, or video Verified by code trace (three independent verification passes). Key contrast: `ConversationView.tsx:338` uses `useThrottledStreamBuffer()`; `HomeProfessorMariChat.tsx` has no throttling import at all. ## Additional context This is effectively a regression-by-omission of the #2878 fix class — which also matches the reporters' sense that battery drain is back "again". Suggested fix, mirroring the existing pattern: (a) accumulate token/thinking deltas in a ref and flush `setWorkspaceTimeline` via the existing `rafThrottle` util (`packages/client/src/lib/raf-throttle.ts`), delivering non-growth transitions (first token, tool/status events, clear) synchronously; (b) memoize `CompactMarkdown`'s parse (`useMemo` on the input text) and `React.memo` the timeline/history items so only the streaming entry re-renders. No behavior change, purely render-cost. Filed alongside #4629 (extension runtime polling) and #4630 (Noodler reconcile scans) from the same mobile-battery investigation. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:49:36 +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#2529
No description provided.