Skip to content

fix(javascript): expand an escaped receiver's methods once (#1495) - #1517

Merged
kaoru0822-kitauji merged 1 commit into
mainfrom
fix/escaped-receiver-method-results
Oct 10, 2026
Merged

kaoru0822-kitauji merged 1 commit into
mainfrom
fix/escaped-receiver-method-results

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1495.

#1471 made an escaped object escape its methods' results as well. objectReferencedValues now returns ObjectMethod nodes, and referencedValues(…, "escape") maps a function to its return and yield expressions. Every call box.mI() escapes box as the receiver (markReceiver). Each of those escapes started a fresh markValue walk: the escaped binding's initializer object, then all N methods, then N return shared identifiers, all resolving to the same shared binding. With N such calls that is N × N work. A CPU profile at N = 4,000 showed markValue and referencedValues dominating, at 12.2 s of 12.2 s.

The escape site has to stay part of each record: escapedPaths entries 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 and new are all expanded through the existing referencedValues. The result is memoized per expression node and path.
  • Identifier leaves that resolve to the same binding (or the same unresolved name) at the same path collapse to one representative. markValue processes such identifiers identically, because everything after binding resolution keys on bindingId, path, effect, site and origin, and those last three come from the current item.
  • The arrayIterationUnknown check that ran before referencedValues now runs on each expanded node (expandedValues), so it still covers nested expansions.
  • Parser-recovered argument holes still expand to nothing.

Write effects are unchanged.

Measured effect

Issue shape, in-process analyzeJavaScriptSemantics:

N main this branch
1,000 792 ms 124 ms
2,000 2,992 ms 253 ms
4,000 12,016 ms 638 ms

rea analyze-javascript-application <dir> --artifact-format directory wall 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 between main and this branch on 50 sources:

  • the 26 writes cases in tests/acceptance/applications/javascriptReturnedReferences.test.ts;
  • the issue shape at N = 300;
  • 23 real JavaScript files from the installed Visual Studio Code and Obsidian apps.

Verification

New tests in javascriptSemanticAnalysis.member_mutations.test.ts:

Other checks:

  • npx vitest run src/domain/javascript src/application/javascript passes (56 files, 994 tests).
  • npm run test:focused on tests/acceptance/applications/{javascript,application}*.test.ts and tests/boundary/mcp/application*.test.ts passes (12 files, 49 tests), including javascriptReturnedReferences.
  • npm run check:fast and npm run docs:check pass. The lint warnings in this file match main (17).

🤖 Generated with Claude Code

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]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@kaoru0822-kitauji
kaoru0822-kitauji merged commit 46c9cba into main Oct 10, 2026
20 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/escaped-receiver-method-results branch October 10, 2026 09:16
@N0zoM1z0

Copy link
Copy Markdown
Collaborator

Independent review after merge 46c9cba0: the reported 2,000-method source now takes 1,159.3 ms in a diagnostic CPU-profile run, compared with 13,337.9 ms on frozen a0e5e9db under the same two-core resource guard. The complete 6,244,884-byte semantic IR keeps exactly the same SHA-256 (e788a8bcf05a302f566bf383d473e3f861e6d8972bf8302a5131efedaa924d39). I have archived my overlapping uncommitted implementation; #1517 owns the production fix.

One portability issue appeared in the merged test: npm run test:focused over the return-reference/iteration public CLI-MCP workflows and adjacent member-mutation/lifetime tests yielded 260 passed and one failed. The only failure is the newly added hard 2,000 ms assertion, observed at 2,332.3 ms on the prescribed two-core environment; the semantic assertions pass. The isolated compiled analysis above is faster, illustrating why a wall-clock limit inside a concurrent correctness suite is unstable.

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.

@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: This merged while I tested, and the merge 46c9cba0 has the same patch. At 4,000 methods, analysis went from 26.2 s to 1.2 s. No answer changed on 154 checked cases, and the shapes that were fast stay fast.

Speed

I timed head ed479f97 against its parent 2bf81277 on main. This is analysis time on Node 24, median of 3.

Methods returning one object base head
250 188 ms 90 ms
1,000 1,791 ms 245 ms
2,000 6,764 ms 498 ms
4,000 26,239 ms 1,234 ms

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.

Other shapes base head
1,000 get().pI = I calls 114.6 ms 117.8 ms
1,000 captured tI = get() calls 185.5 ms 173.7 ms
A chain of 200 wrappers 59.7 ms 59.2 ms
Hermes Desktop (MIT) vendor chunk 1,387 ms 1,399 ms

These four are within noise. The get() and Hermes rows are medians of 9 runs. Their first 3 runs put head 8% and 0.6% slower. In 9 runs, each head median sat inside base's range. The output hash matched base on all four.

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.

Soundness

I 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.

Case set Cases Right Honest unknown Wrong Other
#1449 follow-up 64 11 47 2 4 no shape
#1471 new forms 90 47 38 4 1 SyntaxError

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

  • Head's test file on base.
  • The MCP path, and Node 22 and 26 on the 154 cases.
  • The CLI wall times and the 23 desktop-app files from the PR body.
  • check:fast and lint.
  • Windows and macOS.

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 runs

Analysis time in ms, Node 24 unless named. Each list is base runs, then head runs.

Case base runs head runs
250 methods 185.3, 187.6, 195.8 89.8, 92, 89.6
1,000 methods 1,862.6, 1,783.1, 1,791.4 243.6, 244.8, 245.6
2,000 methods 6,781.1, 6,763.7, 6,694.8 497.9, 490.9, 511
4,000 methods 26,077.8, 26,238.8, 27,218.9 1,230.5, 1,233.7, 1,288
2,000 methods, Node 22 8,519.8, 8,141.6, 8,049.9 623.5, 623.2, 622.8
2,000 methods, Node 26 6,387.9, 6,385.8, 6,464.3 513.8, 539.4, 516
get() calls, first 3 113.9, 113.2, 112.6 122.1, 124.7, 121
get() calls, 9 more 105.9 to 120.4 107.8 to 123.8
Captured calls 185.5, 185.7, 179.9 170.3, 173.7, 186.1
Chain of 200 57.4, 59.7, 60 58.9, 61.1, 59.2
Hermes chunk, first 3 1,430.3, 1,422.5, 1,407.4 1,452.5, 1,429.7, 1,430.5
Hermes chunk, 9 more 1,359.1 to 1,464.4 1,361.1 to 1,446.6

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
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Head / base: ed479f97 / 2bf81277; merged as 46c9cba0, same patch
  • REA: built from source with npm ci and npm run build on Node 24

🤖 Generated with Claude Code (Opus 5.5) 🦊

darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
) (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
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
Iyanuoluwa007 pushed a commit to Iyanuoluwa007/rea that referenced this pull request Oct 21, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Many methods returning one object make analysis grow quadratically since #1471

4 participants