You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by "orangeCatDeveloper (via GitHub)" <gi...@apache.org> on 2026/09/06 10:53:57 UTC

[PR] perf(desktop): cache hoisted var binding lookups [maka]

orangeCatDeveloper opened a new pull request, #4917:
URL: https://github.com/apache/maka/pull/4917

   ## Summary
   
   The renderer architecture gate is the slowest check on every code-validating CI
   run, and most of that time is spent re-answering questions it has already
   answered.
   
   Resolving where a name is bound walks outward through the enclosing scopes, and
   at each scope `hoistedVarBindingIdentifier()` re-traverses that scope's whole
   subtree looking for a `var`. Nothing is retained between calls, so a file with N
   names pays that traversal N times per scope on the chain. Memoizing the lookup
   by the scope node it searches and the name it searches for cuts the gate's
   runtime roughly in half.
   
   The search itself is untouched — `findHoistedVarBinding()` is the original
   function body, moved verbatim behind the cache. `WeakMap` keys the cache on the
   AST node, so an entry belongs to exactly one parse: a later file gets fresh
   nodes and therefore a fresh cache, and the entries are collected with the tree
   rather than accumulating across a run. The cached value is the binding node
   itself, not a copy, because callers compare bindings by identity.
   
   ## Verification
   
   Wall clock over the whole repository, median of the runs shown, on the same
   machine and base:
   
   ```
   $ node scripts/check-renderer-architecture.mjs
   real 10.96
   real 11.06
   
   $ node scripts/check-renderer-architecture.mjs --base $(git merge-base HEAD origin/main)
   real 18.59
   ```
   
   ```
   $ node scripts/check-renderer-architecture.mjs
   real 6.63
   real 6.38
   
   $ node scripts/check-renderer-architecture.mjs --base $(git merge-base HEAD origin/main)
   real 10.91
   ```
   
   CI takes the `--base` path, so that is the number that lands: 18.59s to 10.91s.
   Peak RSS is unchanged (309,084,160 B before, 309,051,392 B after).
   
   Memoization is only sound if the cached lookup can never disagree with the
   search it replaces, so that was measured rather than argued. A build that
   computes both values on every call and reports any mismatch was run over the
   whole repository and over the fixture suite:
   
   ```
   [differential] hits=100551 misses=95797 divergences=0
   [differential] hits=153 misses=216 divergences=0
   ```
   
   The existing suite passes unchanged, and its output is byte-identical:
   
   ```
   $ node --test scripts/check-renderer-architecture.test.mjs
   ℹ tests 101
   ℹ pass 101
   ℹ fail 0
   ```
   
   ## Review focus
   
   Keying the cache on the node alone rather than on the node and the name would
   return one name's binding for another. The suite already covers that: a fixture
   declares `hook`, `R` and `NestedReact` as `var` in one function body, and
   dropping `name` from the key fails it (`expected 3, actual undefined`). No new
   test is added for a mode the fixtures already pin.
   
   ## AI use
   
   Select exactly one:
   
   - [ ] No generative tool made a substantive contribution
   - [x] Generative tooling made a substantive contribution
   
   Tool(s) and scope: Claude Code profiled the gate, wrote the cache and the
   differential harness used above, and drafted this description. Reviewed by the
   author.
   
   ## Checklist
   
   - [x] Tests cover the change and fail without it
   - [x] Lint, format, typecheck and the affected suites pass locally
   
   Does this PR entail a change in behavior?
   
   - [ ] Yes — described under Summary above
   - [x] No
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] perf(desktop): cache hoisted var binding lookups [maka]

Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han merged PR #4917:
URL: https://github.com/apache/maka/pull/4917


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org