[GH-ISSUE #2165] [Feature]: Speed up the ruleset package regression by caching repeated catalog parses and shippedUpTo results #2160

Closed
opened 2026-11-08 00:47:05 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Promansis on GitHub (Nov 7, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/2165

Originally assigned to: @Promansis on GitHub.

What problem does this solve?

The ruleset package regression (scripts/tests/ruleset-package.regression.mjs) takes 10-17 min in CI and about 15m42s locally. Profiling shows three hot spots, all repeated work with the same inputs:

  • assertRulesetSheetHooks in scripts/ruleset-package-checks.mjs re-parses multi-MB catalog text with JSON.parse in nine loops on each of its 959 calls.
  • The "counted" name set inside that function is rebuilt for every entry.
  • shippedUpTo(minor) in the test is called 505 times with only 192 distinct arguments.

Proposed package or change

Repository test code only, no package change.

  1. Checker: a parsedCatalogFile(text) helper (bounded 64-entry map keyed by the text, result deep-frozen, reusing the existing deepFreeze and PARSED_CATALOG_CACHE_SIZE) replaces the nine JSON.parse(String(text)) calls in assertRulesetSheetHooks; countedNames is declared once per call and filled lazily. Freezing makes any later mutation of a cached parse throw (ES modules are strict).
  2. Test: memoise shippedUpTo by minor, returning a structuredClone of the document and a new Map of sources so callers keep their own copies. A VERIFY_MEMO=1 mode re-derives each memoised result and compares it with isDeepStrictEqual, printing the comparison count.

A prototype measured 15m42s → 10m03s with 301/301 checks passing, and VERIFY_MEMO=1 found all 651 memoised results identical to fresh ones.

Why should this be optional?

Not a package. The test's assertions and coverage are unchanged; only repeated parsing and derivation are cached.

Alternatives considered

Splitting the test across CI jobs would cut wall-clock but not compute, and adds workflow complexity. The ruleset workflow is already gated by paths (#2163).

Additional context

Follows #2163 (the ruleset workflow gate). This PR touches scripts/ruleset-*.mjs and the test, so the gated ruleset workflow runs on it.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Promansis on GitHub (Nov 7, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/2165 Originally assigned to: @Promansis on GitHub. ## What problem does this solve? The ruleset package regression (`scripts/tests/ruleset-package.regression.mjs`) takes 10-17 min in CI and about 15m42s locally. Profiling shows three hot spots, all repeated work with the same inputs: - `assertRulesetSheetHooks` in `scripts/ruleset-package-checks.mjs` re-parses multi-MB catalog text with `JSON.parse` in nine loops on each of its 959 calls. - The "counted" name set inside that function is rebuilt for every entry. - `shippedUpTo(minor)` in the test is called 505 times with only 192 distinct arguments. ## Proposed package or change Repository test code only, no package change. 1. Checker: a `parsedCatalogFile(text)` helper (bounded 64-entry map keyed by the text, result deep-frozen, reusing the existing `deepFreeze` and `PARSED_CATALOG_CACHE_SIZE`) replaces the nine `JSON.parse(String(text))` calls in `assertRulesetSheetHooks`; `countedNames` is declared once per call and filled lazily. Freezing makes any later mutation of a cached parse throw (ES modules are strict). 2. Test: memoise `shippedUpTo` by `minor`, returning a `structuredClone` of the document and a new `Map` of sources so callers keep their own copies. A `VERIFY_MEMO=1` mode re-derives each memoised result and compares it with `isDeepStrictEqual`, printing the comparison count. A prototype measured 15m42s → 10m03s with 301/301 checks passing, and `VERIFY_MEMO=1` found all 651 memoised results identical to fresh ones. ## Why should this be optional? Not a package. The test's assertions and coverage are unchanged; only repeated parsing and derivation are cached. ## Alternatives considered Splitting the test across CI jobs would cut wall-clock but not compute, and adds workflow complexity. The ruleset workflow is already gated by paths (#2163). ## Additional context Follows #2163 (the ruleset workflow gate). This PR touches `scripts/ruleset-*.mjs` and the test, so the gated ruleset workflow runs on it. ## Template check - [ ] I DID NOT read this template and provide the requested details.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Agents#2160
No description provided.