Skip to content

perf(core): memoize member-lookup DeclMaps (pure builders) — cut 1 - #179

Merged
matthew-dean merged 3 commits into
devfrom
perf/mixin-lookup-validate
Sep 8, 2026
Merged

perf(core): memoize member-lookup DeclMaps (pure builders) — cut 1#179
matthew-dean merged 3 commits into
devfrom
perf/mixin-lookup-validate

Conversation

@matthew-dean

Copy link
Copy Markdown
Member

Repeated BASE[member] lookups rebuilt their member index per access (measured: a detached-ruleset map read 5× rebuilt the DeclMap 10×). This caches the DeclMap on the resolving frame, keyed by base-node identity, for the pure builders only — collection, namespace-selector, and detached-ruleset body (the @use module path too). Plain Map, not a WeakMap: the frame owns the lifetime and disposes it with the render.

Gated per-arm (never the Reference/MixinCall arms, which consult e.excluded or run expandCall); stored only when no alias cycle is active (e.excluded empty), so a computed key over an actively-excluded alias is never cached; never caches null. Negative control: JESS_NO_DECLMAP_MEMO=1 reproduces the un-memoized path.

Deliberately deferred: the mixin-call dispatch (@p:.mk()[x]) is NOT memoized — it mutates the caller frame (leakBodyVars/publish), so memoizing it isn't observationally free. That's a second cut behind the mixin-scoping decision.

Reviewed by perf-architecture twice (design + implementation): per-arm gating, store guard, WeakMap-free per-render lifetime, and node+frame keying all confirmed correct; byte-transparent on/off. Committed correctness lock: lookup-declmap-memo.test.ts (passes identically with the memo on and off; a sibling-member-reference case proves the memo caches the index, not values). Full core + jess suites byte-identical; ratchet updated (+1 fn, +1 Map; new WeakMap unchanged at 4).

Design: docs/design/MIXIN-SCOPING-AND-LOOKUP-MEMO.md. Unblocks D18 (SCSS module member access) and is the general re-index fix; the caller-scope-leak close (R16) and the mixin-call second cut are tracked there for a later PR.

…re builders)

A repeated `BASE[member]` rebuilt its member index per access (measured: a
detached-ruleset map read 5× rebuilt the DeclMap 10×). Cache the DeclMap on the
resolving frame, keyed by the base node identity, for the PURE builders only —
collection, namespace-selector, and detached-ruleset body (`resolveBaseDeclMap`
Collection / Any-Keyword / resolveForRuleset arms). Plain Map, not a WeakMap: the
frame owns the lifetime and disposes it with the render; a node-keyed WeakMap would
pin DeclMaps for the AST's whole cross-render lifetime.

Gated per-arm (never the Reference / MixinCall arms, which consult e.excluded or run
expandCall); stored only when no alias cycle is being resolved (e.excluded empty), so
a computed key over an actively-excluded alias is never cached; never caches null.
Negative control: JESS_NO_DECLMAP_MEMO=1 reproduces the un-memoized counts. The
mixin-call dispatch (`@p:.mk()[x]`) is deliberately NOT memoized here (it mutates the
caller frame) — deferred to the second cut behind the scoping decision.

Measured (negative control): detached map read 5× → DeclMap builds 10→1. Full core +
jess suites byte-identical; ratchet updated (+1 fn, +1 Map; WeakMap stays 4).

Design: docs/design/MIXIN-SCOPING-AND-LOOKUP-MEMO.md
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 2a9822b3-96e5-4c70-b6a3-fe42a627432e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@matthew-dean
matthew-dean merged commit 926782b into dev Sep 8, 2026
7 checks passed
@matthew-dean
matthew-dean deleted the perf/mixin-lookup-validate branch September 8, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant