mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
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#5806
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?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3118
Author: @kolacheee
Created: 6/30/2026
Status: ✅ Merged
Merged: 7/2/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/3104-macro-engine-perf📝 Commits (3)
fe48df1fix(shared): make macro display resolution linear, not super-linear (#3104)d4b9b92fix(shared): tighten macro fast-path edges found by adversarial audite7e4ff8test(shared): cover macro passthrough optimization📊 Changes
2 files changed (+73 additions, -11 deletions)
View changed files
📝
packages/shared/src/utils/macro-engine.ts(+36 -11)📝
scripts/regressions/prompt.regression.ts(+37 -0)📄 Description
Linked issue
Relates to #3104 — this is the primary per-resolution-cost fix (the macro engine), complementary to #3114 ("Reduce chat area render scope", the re-render-frequency side). It should not auto-close #3104 until an affected user confirms the freeze is gone (see below).
Why this change
A Bottom-Up CPU profile from an affected user pinned the #3104 freeze:
resolveMacrosat 75% self-time (~38s).resolveMacrosruns per message during display render in every mode (ChatMessage,ConversationMessage,GameNarration), so this is the cross-mode cause behind the game / roleplay / conversation reports.The root cause:
resolveMacroseagerly and unconditionally rebuiltpersonaText— resolving all five persona fields, each of which recurses back intoresolveMacroswhen it contains macros — on every call, before checking whether the template even uses{{persona}}. Worse, that rebuild is re-paid at every nested field-resolution frame, so it compounds. On agent chats with large, self-referential persona fields, per-message display resolution goes super-linear. (Introduced by the v2.0.7 macro rewrite,afa0cc3ab.)What changed
Two behavior-preserving changes in
packages/shared/src/utils/macro-engine.ts:resolveMacrosis triggered by either{{(live macros) or the\x1edeferred-character-token sentinel. A template containing neither has nothing to resolve, so it's returned unchanged (with the sametrimResult/clampMacroOutputfinalize) instead of running the comment strip, bracket/conditional expansion, the global substitution passes, and the persona build. This covers the bulk of display content (plain prose).personaText. Build it only when{{persona}}is actually present in the result, keeping the string-replace form so$-sequences substitute exactly as before. This stops the unconditional (and per-recursion-frame) persona rebuild.No budget caps were touched.
MAX_MACRO_EXPANSIONS/MAX_MACRO_OUTPUT_LENGTH/ depth limits are unchanged, so this does not trade speed for unresolved (literal) macros — macros still fully resolve, always for API prompts and on user-visible display content.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
Done by the agent:
pnpm check→ exit 0 (TypeScript + ESLint + build).{{user}}/{{char}},{{persona}}with a$&sequence (string-replace semantics preserved), char-field macros,{{#if}}conditionals, and a\x1edeferred-character token (passed through untouched). Output matched exactly in every case.{{char}}msg 57ms → 0.13ms,{{persona}}msg 58ms → 1.26ms (~50–450×).Still needs manual verification (decisive — don't merge on synthetic/code-reading alone):
chat-areafreeze is gone (their data is what produced the 38s; the synthetic case only proves the shape).{{user}}/{{char}}/{{persona}}and conditionals still render correctly in a real roleplay/conversation/game chat, and that an API prompt (peek-prompt) still fully resolves macros.Docs and release impact
UI evidence (if applicable)
No UI change — macro output is identical; only the cost of producing it changes.
Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.