mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #5513] Every prompt build scans the whole lorebook_entries table for the {{lorebooksize}} macro, used or not #3064
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#3064
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 25, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5513
Originally assigned to: @kolacheee on GitHub.
Found while auditing the #5506 commit window for memory-pressure amplifiers.
Since
34ecca6e9(#5454, the{{lorebooksize::ID}}macro),buildPromptMacroContextunconditionally runslorebooks.countAllEntriesByLorebook()on every prompt build (packages/server/src/services/prompt/macro-context.ts:658-665on staging). That helper materializes one row object per entry across all lorebooks (packages/server/src/services/storage/lorebooks.storage.ts:624-632— a fulllorebook_entriesselect on the file-backed store), and the context is built for main generations, retries, and each agent prompt, so the scan runs several times per user message.Almost no prompt uses the macro, but every generation pays the full-table allocation churn. On large mobile profiles that already sit near the Node heap ceiling (see #5506), this is avoidable GC pressure at exactly the worst moment.
Fix shape: make the count lazy — only call
countAllEntriesByLorebook()when the assembled template actually containslorebooksize(same pattern as other conditionally-computed macro inputs).@SpicyMarinara commented on GitHub (Aug 25, 2026):
@kolacheee I am taking the minimal implementation into one release-hardening PR against staging now, using the fix boundaries from your audit. I will keep your diagnosis credited in the PR and avoid expanding scope beyond the four verified paths.