mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[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
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#2529
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
tokenevent callssetWorkspaceTimeline((current) => appendTextTimeline(current, event.data))immediately (packages/client/src/components/chat/HomeProfessorMariChat.tsx:3385-3392) — no rafThrottle / buffer anywhere in the file.React.memo, so every timeline item and history message re-renders per token.CompactMarkdown(HomeProfessorMariChat.tsx:1149-1160) callsrenderMarkdownBlocks()(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
useThrottledStreamBuffer(packages/client/src/hooks/use-throttled-stream-buffer.ts:9-26, cited to #2878) — same stream, far less render work.Environment
93738d9b1)Logs, screenshots, or video
Verified by code trace (three independent verification passes). Key contrast:
ConversationView.tsx:338usesuseThrottledStreamBuffer();HomeProfessorMariChat.tsxhas 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
setWorkspaceTimelinevia the existingrafThrottleutil (packages/client/src/lib/raf-throttle.ts), delivering non-growth transitions (first token, tool/status events, clear) synchronously; (b) memoizeCompactMarkdown's parse (useMemoon the input text) andReact.memothe 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