mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #8045] [MERGED] perf(rulesets): build live-state schemas once and cache live-less sheet evaluation per combat command #8072
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#8072
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/8045
Author: @Promansis
Created: 10/22/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @Promansis
Base:
staging← Head:feature(rulesets)/8036-sheet-evaluation-cache📝 Commits (4)
3cfd002perf(rulesets): build live-state schemas once and cache live-less sheet evaluation per combat command (#8036)e9ebf9aMerge upstream/staging into feature(rulesets)/8036-sheet-evaluation-cachec22217cfix(rulesets): refuse async work in the sheet evaluation cache scope (#8036)54b2246Merge upstream/staging into feature(rulesets)/8036-sheet-evaluation-cache📊 Changes
5 files changed (+149 additions, -7 deletions)
View changed files
📝
packages/server/src/services/game/ruleset-combat-director.service.ts(+12 -0)📝
packages/shared/src/features/ruleset-combat/hold.ts(+5 -2)📝
packages/shared/src/features/rulesets/live-state.ts(+7 -4)📝
packages/shared/src/features/rulesets/sheet-math.ts(+47 -1)➕
scripts/regressions/ruleset-sheet-evaluation-cache.regression.ts(+78 -0)📄 Description
Linked issue
Closes #8036
Why this change
ruleset-combat-director.regression.ts(the slowest Node regression: 123 s alone, 131–300 s in the CI pool, one pool timeout) put the time in the engine, not the test: 9.7 million live-lessevaluateRulesetSheetcalls for 13,085 distinct sheets, plus 22.8 s spent rebuilding two zod string schemas on every stored live-state read.What changed
Ruleset fight commands are faster. Inside one combat command, each character sheet is now worked out once instead of thousands of times, and reading a fighter's stored live state no longer rebuilds its validators. Nothing a player sees changes: results are the same.
How the cache stays safe:
Outside a command (fight creation, sheet import, the client) evaluation works exactly as before. The scope takes synchronous work only: a callback that returns a promise throws, because the promise would be awaited after the scope had closed. The cache keys on the build object, so it is only sound if nothing edits a build after evaluating it; the doc comment states that rule.
Two places in
hold.tsevaluated a clone and then edited it. Both now read the original instead, which is identical until the edit: the creature-sheet health clamp (holdRulesetSheetHealth, named in the issue) andfillRulesetSheetChoices, which the audit of the issue's write sites found. Both run only increateRulesetFight, outside the scope, so this changes no current result; it keeps them correct if they are ever called inside a command.live-state.ts: the two string schemas are built once at load and shared by the stored-state reader and the live-state schema.New regression
scripts/regressions/ruleset-sheet-evaluation-cache.regression.ts: inside a scope the same sheet returns the same object and live values bypass the cache; outside a scope results are fresh; the health clamp still reports the clamped maximum inside a scope (it reported "is now 200" instead of "is now 67" before thehold.tsfix); a nested scope does not clear the outer one; a scope that throws still closes; a callback that returns a promise is refused, at the top level and nested.Validation
pnpm checkpasses locallyCONTRIBUTING.mdAgent-run checks on
e9ebf9a8d(stagingbe91aab32merged in), Node v24.15.0:pnpm checkreact-hooks/exhaustive-depswarning in client code this PR doesn't touch)node scripts/run-regressions.mjs --concurrency 8(complete Node lane)node scripts/run-regressions.mjs --filter scripts/regressions/ruleset-sheet-evaluation-cache.regression.tsAfter the Dottore repair (
c22217cec), on54b2246b2(staging010829b36merged in):pnpm checknode scripts/run-regressions.mjs --filter ruleset --concurrency 8--concurrency 8pool)node scripts/run-regressions.mjs --filter scripts/regressions/ruleset-sheet-evaluation-cache.regression.ts, case (e)Evidence:
hold.tshealth line reverted to read the clone): the new regression fails with "…and is now 200".After: it passes in under a second.
ruleset-combat-director.regression.ts123 s alone (issue baseline, CI-class runner).After: 52.9 s alone on the worker's machine, 77.9 s inside the full local pool (
--concurrency 8).After: 56.0 s and 124.1 s inside that pool on this PR's two runs (jobs 119678441872 and 119724308944), no timeout.
Manual verification notes
staging, and turns should come back noticeably faster.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)Merge danger: two-way door (no stored data or format changes; reverting the commit restores the old path). Blast radius: ruleset combat commands on the server.
UI evidence (if applicable)
Not applicable: no UI change.
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.