Repository navigation
fix(javascript): yield during the largest AST traversals - #1545
Conversation
After #1542 the longest event-loop blocks on large bundles were single AST traversals inside one analyzer: member-mutation collection with its fixpoint, static source analysis, and function fingerprints, each about one second on Obsidian's 3.7 MB app.js. - traverseJavaScriptAstSteps yields every 1,024 visited nodes with the same visit order; traverseJavaScriptAst drains it, so every existing caller is unchanged. - Member mutations, static analysis and fingerprints run as steps. The member-mutation fixpoint yields every 64 references, and fingerprints yield between callables. - The now-unused synchronous member-mutation and fingerprint wrappers are removed. Graph IDs and complete result digests match main on three inputs, including obsidian.asar. Over two runs there, the longest block falls from about 920 ms to 740 ms, the second from 860 to 595 ms, and blocks over 250 ms from 27 to 18, with total time within 1.5%. Refs #1462 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 constrained Linux x64 review of final author head
Node 24.18.0; CPU affinity 13/15 verified on actual child processes; one heavy lane at a time; each process family remained below the unchanged 2304 MiB budget (peaks 1,829,740,544–1,881,440,256 bytes). These are two observations per revision, not a latency percentile or general throughput claim. The initially apparent 20% slowdown was not stable: the repeated main control was slower than both candidate runs. Candidate control waits stayed under a second in these two runs, while main's observed maximum varied considerably. Warmed-SDK 1,200-function cancellation at about 200 ms also passed on both revisions: the following ping waited 17.96 ms on main and 36.11 ms on the candidate, cancelled analyses retained zero Evidence, subsequent small analysis and cleanup succeeded. This is correctness/recovery evidence, not an improvement claim for that small cancellation fixture. This is a useful partial #1462 improvement. Remaining synchronous passes/parsing and unsampled stalls are not ruled out; #1462 should stay open. No real Hopper/Ghidra verification was performed for this JavaScript-only change. |
After morluto#1542 the longest event-loop blocks on large bundles were single AST traversals inside one analyzer: member-mutation collection with its fixpoint, static source analysis, and function fingerprints, each about one second on Obsidian's 3.7 MB app.js. - traverseJavaScriptAstSteps yields every 1,024 visited nodes with the same visit order; traverseJavaScriptAst drains it, so every existing caller is unchanged. - Member mutations, static analysis and fingerprints run as steps. The member-mutation fixpoint yields every 64 references, and fingerprints yield between callables. - The now-unused synchronous member-mutation and fingerprint wrappers are removed. Graph IDs and complete result digests match main on three inputs, including obsidian.asar. Over two runs there, the longest block falls from about 920 ms to 740 ms, the second from 860 to 595 ms, and blocks over 250 ms from 27 to 18, with total time within 1.5%. Refs morluto#1462
Refs #1462. This is the next step after #1525 and #1542, splitting the largest remaining single-traversal blocks inside the analyzers.
Change
traverseJavaScriptAstSteps(javascriptSemanticTraversal.ts) is the existing explicit-stack traversal with a yield every 1,024 visited nodes. Visit order,readAncestorsandexitare unchanged.traverseJavaScriptAstdrains it, so the traversal loop exists once and all existing callers behave as before.completeSemanticStepsis the shared drain helper.collectSemanticMemberMutationsSteps): both traversals are stepwise, and the pending-reference and iterable fixpoint loops yield every 64 references. Visit and fixpoint order are unchanged.analyzeParsedJavaScriptStaticSourceSteps): the source traversal is stepwise.analyzeParsedJavaScriptStaticSourceremains as the synchronous form.collectJavaScriptSemanticFingerprintsSteps): a yield between callables, plus a stepwise subtree traversal per callable. A bundle wrapper's subtree can be the whole file. Callable order and digests are unchanged.yield*into these. The synchronous member-mutation and fingerprint wrappers had no remaining callers and are removed.Results are identical
reconstructJavaScriptArtifacton currentmain(ca7ef69c, after #1542) and on this branch gives the same application graph ID, semantic graph ID and SHA-256 of the complete serialized result for:app.asar;obsidian.asar(23 MB).Measured effect
Obsidian
obsidian.asar, full in-process analysis with a 1 ms event-loop gap monitor, two runs each, M-series Mac:Remaining
The remaining blocks of about 0.5–0.75 s include:
These can be converted the same way. Each step is smaller, so I kept this PR to the three largest.
Verification
javascriptSemanticAnalysisSteps.test.tshas a new test: the step traversal yields on a 400-statement file and records exactly the synchronous enter/exit sequence. The existing semantic-steps equality test now also exercises the stepwise member-mutation and fingerprint passes.npx vitest run src/domain src/applicationpasses (171 files, 2,139 tests).npm run test:focusedon the JavaScript composition, acceptance and analysis-view boundary suites passes (20 files, 112 tests).npm run check:fastandnpm run docs:checkpass. Lint warnings in the touched files matchmain(pre-existing complexity,max-linesandmax-params).🤖 Generated with Claude Code