mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3164] [Issue]: Regex scripts apply per-streaming-chunk & cause severe UI freezes #1695
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#1695
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 @atlasveldine on GitHub (Jul 3, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3164
Originally assigned to: @kolacheee on GitHub.
Summary
Using RegEx scripts that replace with macros results in massive UI lag, rendering Marinara Engine effectively unusable. Thank fuck for whoever came up with the idea to implement such a competent agent with the built-in
Mari, because otherwise I’d not have anything else to report beyond “shit be fucked.” Practically everything ↓ below ↓ is fromMari.Mari’s Breakdown
File/Function:
ChatRoleplaySurface, specifically the useMemo in message rendering around line ~1700. It callsapplyToAIOutput(the client-side regex function, imported fromPinnedImageOverlay, functionre) with amacroResolverthat gets updated every streaming chunk. Since the memo depends on content, every single token invalidates it, re-running the full regex pipeline for all visible messages simultaneously. Each regex script compiles a freshRegExp, resolves macros infind/replace/trimStringsvia the macro engine, and worse, if replacements contain{{random::…}}or other dynamic macros, they produce new results every chunk instead of remaining stable. This blocks the main thread for hundreds/thousands of milliseconds (profiler showed 702ms inmacro-engine-qQkcw39S.jsat a bare minimum, but went well into the 3,000ms range).Suggested Fix
Move regex application out of the per-message useMemo, apply only to the final message content post-stream, and cache resolved macro values for each script so they don't re-evaluate on every render. Optionally, offload the heavy lifting to a web worker.
Expected behavior
RegEx scripts should probably apply only once, when the stream finishes and the message is completed. If the message is edited later, re-apply at that point. Compare to SillyTavern/RisuAI: they don't burn the main thread on every token. (Although they do have their own issues with UI lag from other sources, still.)
Actual behavior
RegEx is applied per-chunk when streaming, and bizarrely even randomly re-applies outside of streams, causing massive compounding UI lag.
Steps to reproduce
Enable regex script(s) with macro-containing replace strings (even simple ones) and start streaming a response. The UI will freeze. Disabling all regex scripts restores full performance.
Specifically, if you really want to trigger this, try RegEx like:
With a replacement of e.g.:
Repeat this with a few additional ones for good measure (targeting other common words) and watch your UI lag to hell and back in Roleplay mode. UI lag will even occur outside of generation, bafflingly.
Environment
Logs, screenshots, or video
Additional context
For anyone else dealing with this issue: just disable any RegEx scripts that replace with macros, in the meantime.
Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked: