Repository navigation
fix(javascript): bound member-mutation paths through reassignment loops - #1390
Conversation
Since morluto#1292, member-mutation propagation carries a separate property path per binding state. A loop that reassigns one reference through k members can prepend those members in any order, so the number of distinct paths grows factorially: nine members take 7 s and ten exhaust the heap. The React vendor chunk of Hermes Desktop needs more than 5 GB and crashes the analysis. Union the paths that reach each binding state into one covering path. An effect at a path already applies to every extension of it, so the covering path keeps every effect of the paths it replaces while the work stays bounded. The vendor chunk now analyzes in 1.7 s and 190 MB, and sixteen members take 20 ms. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01XPY2GmufMNGQKoEgRUx1pd
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Maintainer investigation against
The full Notion ASAR workflow still has a separate severe hotspot: the precise-path follow-up reaches the main bundle in about 5 seconds, finishes that bundle around 24 seconds, and then remains inside the activity-monitor renderer semantic pass until the 210-second client deadline. A concurrent ping hits its separate 45-second deadline. This does not establish a passing whole-application performance or cancellation result. I am collecting the renderer's CPU profile before making a broader performance claim. No provider-dependent claim is changed or verified by these static JavaScript checks. Target executable bytes remain unchanged. |
|
TL;DR: The speedup is real. Loops that took minutes now take milliseconds. But the fix can now report a wrong value. In one case it says a field is still 1 when the code can set it to 2. I think that needs a fix before merge. Other jobs ran on the box at the same time, so base times are noisy. SpeedThis is your loop snippet with k members. The heap was capped at 3,000 MB. Head times are the median of 3 runs. Base got one run.
Every run that finished said Wrong valueconst shared = { x: 1 };
const o = { child: shared };
const t = flag ? o.child : o;
t.x = 2;
return shared.x;When The same thing happens in the loop shape this PR targets: const inner = { v: 1 };
const seed = { m0: inner };
let node = seed;
let i = 0;
while (i++ < 1) { node = flag ? node.m0 : node; node.v = 2; }
return inner.v;Real JS returns 2 here. Base says Lost precisionThese are still sound, just coarser:
The new test checks that the result stays Real appI ran Tests
Not run at first (now done)Edit: done. The results are in my follow-up comment.
Thanks, marnixpluim, for the clear write-up and the small repro. It made this easy to test. How I read itHere is how I read it. One idea, which I have not tried: keep the covering path only to skip repeats. Then pass the original path on to the initializers. Or never let a union go below what the write guards need. You know this code better than I do. Test setup
🤖 Generated with Claude Code (Opus 5.5) 🦊 |
The covering path from the previous commit unioned every path that reached a binding state. Review found two problems: - Initializers pass on only writes at least two keys deep, so a shorter write path never reaches the objects a longer one does. Unioning ["x"] with ["child", "x"] gives [null], so after `const t = flag ? o.child : o; t.x = 2` the child's `x` still read as 1. Prefix coverage has the same hole: ["child"] does not cover ["child", "child"] for a write. - Unioning paths through different first members, such as ["left"] and ["right"], gives [null] and makes every member of the binding unknown. Key the covering path by its first member as well, and for writes by its length. A union then never changes which members of a binding are affected, and a write covers only writes of its own length. The nine-member loop stays in milliseconds for both a call and a write.
|
Thanks, both. You were right: the covering union was unsound for writes, and it also lost the precision N0zoM1z0 measured. 56a40a4, on top of the original commit, fixes both. Cause. Initializers pass on only writes at least two keys deep, so a shorter write path never reaches the objects a longer one does. Change. The covering path is now keyed by the path's first member as well, and for writes by its length. A union never changes which members of a binding are affected, and a write covers only writes of its own length. Escapes keep prefix coverage. This is close to CassieFox23's second idea.
These are now tests in Real bundles through
On all ten bundles that finish on Not changed here: a write through a loop that walks the same member twice is already lost on Checks on @N0zoM1z0 this keeps your three cases at literal Generated by Claude Code |
|
Thanks for adding the write-depth regressions in One precision gap remains at this head: grouping by the first member still widens deeper, unrelated members that share that prefix: export function result() {
const shared = { left: { value: 1 }, right: { value: 2 }, keep: { value: 3 } };
const source = { nested: shared };
const alias = flag ? source.nested.left : source.nested.right;
mutate(alias);
return shared.keep.value;
}Baseline The follow-up keeps exact member prefixes, separates write depths, and canonicalizes suffixes only where observed container/prototype origins cannot distinguish their effects. It also stops reevaluating mutations after a value is already terminally unknown. Current main plus the follow-up passes the semantic suite and static gate; an earlier frozen build completed the real Notion ASAR workflow through MCP and CLI with matching Evidence identity for identical ASAR input. I am refreshing the real proof for the final source before pushing the follow-up here. Cancellation and event-loop responsiveness remain separately tracked in #1065. |
Retain exact observed member paths and equal-depth write coverage. Canonicalize suffixes only beyond statically observable container and prototype origins, and stop replaying mutations after a binding value becomes terminally unknown. Preserve both affected conditional paths and unrelated nested siblings. Retain the original contributor's write-depth regressions and commits. Refs morluto#1401, morluto#1065 Co-Authored-By: Marnix Pluim <[email protected]>
|
Confirmed. Your nested case gives literal I won't push to this branch until your follow-up lands. Once it's here, I'll run the regression cases and the twelve-bundle timing from my last comment against it and post the numbers. Generated by Claude Code |
|
TL;DR: I checked Results on the new head
The wrong-value cases now say One case leftThe new key splits paths by their first member only. Two paths that split at the second member still merge. Then a third member at that level reads as changed. This passes on main and fails on the new head with it.each([
"mutate(source.inner.left, source.inner.right);",
"const alias = flag ? source.inner.left : source.inner.right; alias.value = 2;",
])("keeps nested members outside the mutated paths: %s", (body) => {
const program = [
"const source = { inner: { left: { value: 1 }, right: { value: 2 }, keep: { value: 3 } } };",
body,
"return source.inner.keep.value;",
].join(" ");
expect(resultValue(program)).toEqual({ status: "literal", value: 3 });
});It is sound, just coarser. So it may be fine as a known limit. Slower vendor chunkThis is the Hermes Desktop (MIT) chunk from your PR body, on Node 24:
Both commits give the same output on it. This matches your React chunk numbers. Not run
Thanks again, marnixpluim, for the quick turn and the clear table. And thanks to the maintainer for the review. Test setup
More results
Commands# chunk build, in its own folder
npm ci --ignore-scripts
node ../../node_modules/vite/bin/vite.js build
# chunk and loop timing: analyzeJavaScriptSemantics on the built dist/
node --max-old-space-size=5000 run.mjs <tree> module vendor-react-C4pS_tun.js
# real app
node scripts/rea.mjs analyze-javascript-application app.asar --format json
# tests and checks, Node 24
npm run check:ci
npm run verify:test-discovery
npm test🤖 Generated with Claude Code (Opus 5.5) 🦊 |
|
TL;DR: This merged while I was testing. So this is a post-merge check. I tested Results
I ran 59 small cases on both trees and in real JS. The 53 that finish on main give the same result on Hermes Desktop (MIT) vendor chunk
Wrong on main, and unchanged hereReal JS returns 2 for both of these. Main and const shared = { x: 1 };
for (const t of [shared]) t.x = 2;
return shared.x;const g = { v: 1 };
const c = { m0: g, v: 1 };
const seed = { m0: c };
let node = seed;
let i = 0;
while (i++ < 2) { node = node.m0; node.v = 2; }
return g.v;The second one is the loop marnixpluim described. Both are outside this PR. The first one is #1428. Not runEdit: Results for these are in the follow-up. The maintainer's own app is still not run.
Thanks, N0zoM1z0, for the follow-up and the clear commit notes. And thanks, marnixpluim, for keeping the tests in. Test setup
Case notes
Commands# each case, on each tree: analyzeJavaScriptSemantics on the built dist/
node --max-old-space-size=3000 run.mjs <tree> file <case.js>
# real JS: each case in a fresh vm context, over many flag orders
node realjs.mjs <case.js>
# the chunk
node --max-old-space-size=5000 run.mjs <tree> module vendor-react-C4pS_tun.js
# tests
node node_modules/vitest/vitest.mjs run src/domain/javascript/javascriptSemanticAnalysis.reference_lifetimes.test.ts
node node_modules/vitest/vitest.mjs run src/domain/javascript🤖 Generated with Claude Code (Opus 5.5) 🦊 |
|
TL;DR: I ran the rest of my "Not run" list on Checks
All 43 failures were Hopper socket tests. The socket goes in the temp folder. My temp path made it 120 bytes. Linux allows 108, so Real appI used the Beyond All Reason launcher (launcher code MIT; Flathub package GPL-2.0-or-later). All runs used Node 24.
For MCP I copied the limits from the maintainer comment. That meant 2 CPUs, a 210 s call limit, and a ping with a 45 s limit. Every ping came back. The slowest took 5.9 s. Both trees end the call with the same Still not run
Commands# fresh export of 03a960eb, npm ci and build on Node 24
npm run check:ci
npm run verify:test-discovery
npm run test:prepare
node node_modules/vitest/vitest.mjs run
# the 9 failed files again, short TMPDIR, then the long one
TMPDIR=<short dir> node node_modules/vitest/vitest.mjs run <files>
# Node 22 and 26
node node_modules/vitest/vitest.mjs run src/domain/javascript
# real app, CLI, 3 rounds, base and head in turn
nice -n 10 node --max-old-space-size=6000 <tree>/scripts/rea.mjs \
analyze-javascript-application app.asar --format json > out.json
# real app, MCP, 2 rounds: SDK 2.3.1 stdio client,
# 210 s call limit, a ping every 5 s with a 45 s limit
taskset -c 0,1 nice -n 10 node --max-old-space-size=4096 mcp-app.mjs <tree> app.asar
Test setup
🤖 Generated with Claude Code (Opus 5.5) 🦊 |
Original contribution by Marnix Pluim; both original commits and their write-depth regressions are retained.
Reassignment loops introduced by #1292 can enumerate factorially many member-reference paths. Nine members took 28.36 seconds on frozen main
7aa4d768, and the real Notion ASAR did not finish within the 180-second guard. The repaired analysis completes while preserving both affected child bindings and unrelated sibling facts.Fixes #1401. Refs #1065. This does not establish a common cause for #1387.
The collector now visits shallower paths first and retains exact covering prefixes instead of unioning different member keys. Write coverage includes path depth because a short write to an owned slot cannot replace a longer write reaching a shared child. A field-sensitive fixed point tracks observable object/array and Array-prototype origins; suffixes are canonicalized only where those origins cannot distinguish their effects. Dynamic selections, copied references and uncertain origins remain conservative. Value evaluation stops once mutation results are terminally unknown.
Regression coverage includes both conditional alias paths, deeper writes, untouched siblings below a shared prefix, unknown-slot presence, Array-prototype aliases, and loops rooted in unobserved/scalar values. No CLI/MCP contracts, tool inventory, target execution or provider authority change.
Validation on final source
03a960ebace7ab36dd9be78e2ba4399b9f6ade39, incorporating main4d8ef3f3, pinned Node 24.18.0/npm 11.16.0, Linux x64:npm run check:fast, changed-file formatting, module boundaries, whitespace checks andnpm run build:cachedpassed. The local single-threaded compiler preserves the full checking scope under the existing two-CPU resource guard.97c41bc14fc0ea8c91cd34f502660963dfdf294d5eb35165ccac9d30963069d4: actual SDK 2.3.1 stdio MCP analysis took 100.15 seconds, whole workflow 120.26 seconds, and process-family peak RSS was 1.81 GiB. The caller allowed 210 seconds; this is not a default 60-second deadline claim.Large-file responsiveness/cancellation remain open in #1065: longest observed ping was 19.17 seconds, chiefly during graph validation/sealing. This proves the tested loop regression and real artifact completion, not a universal bound for all JavaScript alias graphs. Real Hopper/Ghidra verification is not applicable to this static JavaScript change.