Skip to content

fix(javascript): yield during the largest AST traversals - #1545

Merged
N0zoM1z0 merged 1 commit into
mainfrom
fix/javascript-traversal-steps-2
Oct 10, 2026
Merged

N0zoM1z0 merged 1 commit into
mainfrom
fix/javascript-traversal-steps-2

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

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, readAncestors and exit are unchanged. traverseJavaScriptAst drains it, so the traversal loop exists once and all existing callers behave as before. completeSemanticSteps is the shared drain helper.
  • Member mutations (collectSemanticMemberMutationsSteps): both traversals are stepwise, and the pending-reference and iterable fixpoint loops yield every 64 references. Visit and fixpoint order are unchanged.
  • Static analysis (analyzeParsedJavaScriptStaticSourceSteps): the source traversal is stepwise. analyzeParsedJavaScriptStaticSource remains as the synchronous form.
  • Fingerprints (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.
  • Wiring: semantic analysis, derived collection and per-file analysis yield* into these. The synchronous member-mutation and fingerprint wrappers had no remaining callers and are removed.

Results are identical

reconstructJavaScriptArtifact on current main (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:

Measured effect

Obsidian obsidian.asar, full in-process analysis with a 1 ms event-loop gap monitor, two runs each, M-series Mac:

longest block 2nd blocks > 250 ms total
main 936 / 911 ms 866 / 862 ms 28 / 26 40.0 / 39.6 s
this branch 758 / 736 ms 599 / 591 ms 19 / 18 40.7 / 40.3 s

Remaining

The remaining blocks of about 0.5–0.75 s include:

  • smaller traversals still run synchronously: definitions, open-receiver classification, references, and the data-effect helpers;
  • Babel's parse, which can't be split;
  • some apparently GC-bound pauses during sealing, on a heap of about 1.6 GB.

These can be converted the same way. Each step is smaller, so I kept this PR to the three largest.

Verification

  • javascriptSemanticAnalysisSteps.test.ts has 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/application passes (171 files, 2,139 tests).
  • npm run test:focused on the JavaScript composition, acceptance and analysis-view boundary suites passes (20 files, 112 tests).
  • npm run check:fast and npm run docs:check pass. Lint warnings in the touched files match main (pre-existing complexity, max-lines and max-params).

🤖 Generated with Claude Code

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]>
@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.

@N0zoM1z0

N0zoM1z0 commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Independent constrained Linux x64 review of final author head fe5650bd57ccbaf75f8311047e811207695ead42, integrated with main 539a0f95 as 4e507f29:

  • 202 focused tests passed across 8 files: semantic steps, mutation/reference behavior, static member depth, application/composition cancellation, actual CLI SIGINT, SDK MCP cancellation, and public wide-object/array regressions. npm run check:fast passed.
  • 30 complete serialized domain-IR comparisons matched current main, including duplicate static names, trailing computed properties, both spread orders, getters, lexical captures and dynamic selection.
  • Four complete real ASAR SDK stdio MCP workflows, ordered A1/B1/B2/A2, preserved the exact complete Evidence ID ev_fbe07b5de34746c9191fadb98a2bf6a33d00c9073baa690c75db5c4df3618d98 on unchanged input SHA-256 97c41bc14fc0ea8c91cd34f502660963dfdf294d5eb35165ccac9d30963069d4. Each passed retained summary/module-page/feature trace, identity rejection, ping, close and expired-reference checks.
Observation Analysis latency Longest sampled 1-second ping wait
main first 77.33 s 1242.21 ms
candidate first 92.89 s 549.97 ms
candidate repeat 89.71 s 936.30 ms
main repeat 98.19 s 4710.66 ms

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.

@N0zoM1z0
N0zoM1z0 merged commit 5d6eeb2 into main Oct 10, 2026
20 checks passed
@N0zoM1z0
N0zoM1z0 deleted the fix/javascript-traversal-steps-2 branch October 10, 2026 12:27
darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
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
@morluto morluto added bug Something isn't working area: domain Domain logic, errors, and pure functions labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants