Repository navigation
fix(javascript): expand an escaped receiver's methods once (#1495) - #1517
Conversation
Since #1471, escaping an object also escapes every method's results. Each call through the object escapes it as the receiver, and each escape re-expanded all of its methods. N methods returning one shared object, each called once, did N times N work: 2,000 calls took 3.0 s of semantic analysis and 4,000 took 12 s. Expansion below references depends only on syntax, so escapes now reuse it per expression and path. Identifiers that resolve to the same binding and path collapse to one, because the escape walk treats them alike. Every escape site is still recorded. The semantic IR is byte-identical on 50 sources, and the issue's case takes 253 ms at 2,000 and 638 ms at 4,000. Closes #1495 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Independent review after merge One portability issue appeared in the merged test: I am preparing a small follow-up that keeps the wide receiver semantic regression, removes that hardware-dependent assertion, and adds public CLI/MCP checks for distinct lexical bindings and property paths. Performance measurements stay as explicit diagnostic evidence; this does not claim to finish #1462. |
|
TL;DR: This merged while I tested, and the merge SpeedI timed head
Base costs 3.9 times as much from 2,000 to 4,000. Head costs 2.5 times as much. At 2,000, head is 12 to 14 times faster on Node 22, 24 and 26. The output hash matched base at every size.
These four are within noise. The The box was quiet. The load average stayed between 0.7 and 2.5. That number counts programs running or waiting for one of the 24 CPU threads. SoundnessI ran each case through the CLI on Node 24. I also ran each case in real JS on Node 24 to get the right answer.
The counts are the same on base and head. No answer changed. The full CLI output was also the same on all 154 cases. The 4 getter rows from #1494 stay wrong on base and head. The other 2 wrong rows are writes from another ES module. The 4 rows with no shape are the CommonJS cases. Tests
Not run
Thanks, kaoru0822-kitauji, for the fix and the clear notes on why each escape site stays. The "Same results" section made this easy to check. Raw speed runsAnalysis time in ms, Node 24 unless named. Each list is base runs, then head runs.
All 96 runs exited 0. The issue reported 7,048 ms at 2,000 for #1471. Base here took 6,764 ms. Base is a newer main commit, and the box was quieter. The PR body has smaller times than mine. At 4,000, it lists 12,016 ms on main and 638 ms on the branch. Both trees run about 2 times slower on my box, so the speedup still agrees. The PR body shows 18.8 times at 4,000, and I measured 21.3 times. I did not look into why my box is slower. Test setup
🤖 Generated with Claude Code (Opus 5.5) 🦊 |
) (morluto#1517) Since morluto#1471, escaping an object also escapes every method's results. Each call through the object escapes it as the receiver, and each escape re-expanded all of its methods. N methods returning one shared object, each called once, did N times N work: 2,000 calls took 3.0 s of semantic analysis and 4,000 took 12 s. Expansion below references depends only on syntax, so escapes now reuse it per expression and path. Identifiers that resolve to the same binding and path collapse to one, because the escape walk treats them alike. Every escape site is still recorded. The semantic IR is byte-identical on 50 sources, and the issue's case takes 253 ms at 2,000 and 638 ms at 4,000. Closes morluto#1495
The morluto#1495 regression test required 2,000 receiver calls to finish within 2 s. CI shards run with v8 coverage on slower runners: the test took 1.9 s on morluto#1517's run and 3.2-3.6 s on main afterwards, failing every PR. It now compares the fastest of two runs at 1,600 and 400 calls. That ratio is about 5-6x for the fix, with or without coverage, and about 13-14x for the quadratic code before morluto#1517, so the bound of 10 holds on any runner while still catching the regression.
Summary
Fixes #1495.
#1471 made an escaped object escape its methods' results as well.
objectReferencedValuesnow returnsObjectMethodnodes, andreferencedValues(…, "escape")maps a function to its return and yield expressions. Every callbox.mI()escapesboxas the receiver (markReceiver). Each of those escapes started a freshmarkValuewalk: the escaped binding's initializer object, then all N methods, then Nreturn sharedidentifiers, all resolving to the samesharedbinding. With N such calls that is N × N work. A CPU profile at N = 4,000 showedmarkValueandreferencedValuesdominating, at 12.2 s of 12.2 s.The escape site has to stay part of each record:
escapedPathsentries are compared against capture points (semanticEscapeFollowsCapture). Dropping later sites would lose uncertainty. What does not depend on the site is the syntax below a reference. So for escape effects only:escapedReferenceLeaves(expression, path)flattens the expansion of a non-reference expression down to identifier, member and iterable leaves. Literals, objects, arrays, functions, classes, conditionals andneware all expanded through the existingreferencedValues. The result is memoized per expression node and path.markValueprocesses such identifiers identically, because everything after binding resolution keys onbindingId, path, effect, site and origin, and those last three come from the current item.arrayIterationUnknowncheck that ran beforereferencedValuesnow runs on each expanded node (expandedValues), so it still covers nested expansions.Write effects are unchanged.
Measured effect
Issue shape, in-process
analyzeJavaScriptSemantics:rea analyze-javascript-application <dir> --artifact-format directorywall time, which includes about 0.8 s of startup: N = 2,000 went from 4.99 s to 2.08 s, and N = 4,000 runs in 3.26 s.Same results
The semantic IR (
analyzeJavaScriptSemantics, serialized) is byte-identical betweenmainand this branch on 50 sources:writescases intests/acceptance/applications/javascriptReturnedReferences.test.ts;Verification
New tests in
javascriptSemanticAnalysis.member_mutations.test.ts:shared.tokenunknown. This follows the precedent of 1ec490f. Onmain's implementation it fails (3.2 s); here the whole file runs in about 0.4 s.Other checks:
npx vitest run src/domain/javascript src/application/javascriptpasses (56 files, 994 tests).npm run test:focusedontests/acceptance/applications/{javascript,application}*.test.tsandtests/boundary/mcp/application*.test.tspasses (12 files, 49 tests), includingjavascriptReturnedReferences.npm run check:fastandnpm run docs:checkpass. The lint warnings in this file matchmain(17).🤖 Generated with Claude Code