mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #7730] [MERGED] perf(memory): build message lookups once per reply, not per stored memory #7902
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#7902
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/7730
Author: @SpicyMarinara
Created: 10/16/2026
Status: ✅ Merged
Merged: 10/16/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/7702-memory-prepare-maps📝 Commits (2)
2d2bd8dperf(memory): build message lookups once per reply, not per stored memory5235923docs(memory): note when the per-context message lookups stay valid📊 Changes
2 files changed (+192 additions, -14 deletions)
View changed files
📝
packages/server/src/services/advanced-memory.ts(+50 -14)➕
scripts/regressions/advanced-memory-prepare-scale.regression.ts(+142 -0)📄 Description
Linked issue
Closes #7702
Why this change
recordValid), and each check rebuilt an id map of the whole chat, searched it twice for indexes and ran a full visibility selection. Rendering each recalled scene ran another full selection just to find the persona's name. So the work was (stored memories × chat messages), about 4,000 × 9,600 at 800 scenes.What changed
recordValidandrenderEntrynow share one lookup per context and message list: each message's position, and each view's selection (all messages, the scene archive's view, or what an audience may read), made once and reused for every record. Keyed by the context object and the message array, so a derived context (a historical cutoff, a fresh read after a write) gets its own.sceneSourceaccepts a read-only message list, matchingallowed.scripts/regressions/advanced-memory-prepare-scale.regression.ts: it counts how often one prepare reads each message's details, at 20 and at 80 summarized scenes. Before this change that went from 188 to 668 reads per message (the regression fails); now it stays the same (about 28 per message at both sizes).Validation
pnpm checkpasses locallyCONTRIBUTING.mdAgent-run checks (offline harness, synthetic chats with 12 messages per scene, fake helper/Decision/embedding server, medians of 7 prepares):
The machine was shared with other jobs, so absolute times run higher than the 4.7 s in the issue; each before/after pair ran back to back. What is left grows in step with the archive (reading the stored records, ranking them), no longer with archive × chat length.
prepare()results (Decision on and off, at the newest message and 40 messages earlier) andstatus()are identical before and after at 200 and 800 scenes, apart from the creation times of the records each run saves.advanced-memory*files and the 3memory-*files pass, including the new one; the new one fails on staging (187.9 at 20 scenes, 667.5 at 80).tscfor shared, server, client and root; prettier on the changed files.Manual verification notes
Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)No docs, UI or copy changes.
UI evidence (if applicable)
Not applicable: server-only change.
🤖 Generated with Claude Code
Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.