Skip to content

fix(javascript): yield inside semantic analysis and large projection passes - #1542

Merged
kaoru0822-kitauji merged 2 commits into
mainfrom
fix/javascript-semantic-analysis-steps
Oct 10, 2026
Merged

kaoru0822-kitauji merged 2 commits into
mainfrom
fix/javascript-semantic-analysis-steps

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Refs #1462. This follows #1525. That PR split the per-file work into stages and made graph construction and sealing stepwise. It noted single stages on very large files as the remaining blocks; this PR splits the largest of them.

Where the time was (Obsidian app.js, 3.7 MB, current main)

stage time
parse 326 ms
open-receiver classification 612 ms
static analysis 984 ms
semantic analysis (analyzeParsedJavaScriptSemantics), one step 5,765 ms
└ derived collectors: calls 359, promises 158, async 175, child processes 301, data 761, resources 326, objects 227, fingerprints 958 3,087 ms
└ member mutations 988, definitions 459, references 390, returns 218, bindings 164, module links 110
projection: projectSemanticObjects 1,807 ms
projection: node creation, then definitions/references ~730 + ~760 ms

Open-receiver classification and static analysis also ran in the same step (about 1.6 s).

Change

  • Domain: analyzeParsedJavaScriptSemanticsSteps and collectJavaScriptDerivedSemanticsSteps yield between phases and between collectors. The existing synchronous functions drain them, so every caller and result is unchanged. Each phase completes before the next starts.

  • Per-file analysis yields between open-receiver classification and static analysis, and uses yield* into the semantic steps.

  • Projection:

    • semantic node creation (callables, bindings, return sites, call sites), projectDefinitionsAndReferences, projectSemanticObjects and projectSemanticFrontiers yield every 64 items;
    • a projection pass may now return steps.

    Node creation still runs in source order, which the per-file node budget (SEMANTIC_GRAPH_FILE_NODE_CEILING) depends on.

Everything is driven by the existing time-sliced completeJavaScriptAnalysisSteps, with its 8 ms slices and abort checks.

Results are identical

reconstructJavaScriptArtifact on current main and on this branch gives the same application graph ID, semantic graph ID and SHA-256 of the complete serialized result for:

Measured effect

Full in-process analysis of obsidian.asar, with a 1 ms event-loop gap monitor:

longest block next longest total
main (b88d8f85, after #1525) 5,355 ms (app.js) 4,141 ms (mermaid.min.js) 40.6 s
this branch 907 ms 870 ms 39.5 s

Remaining

The remaining blocks of up to about 0.9 s are single AST-traversal passes inside the analyzers: member mutations, fingerprints, static analysis, receiver classification. Going lower needs a stepwise traverseJavaScriptAst threaded through those collectors. That's a separate change, so #1462 stays referenced, not closed.

Verification

  • New src/domain/javascript/javascriptSemanticAnalysisSteps.test.ts: the stepwise analysis yields at least once per phase and collector, and returns exactly the synchronous IR.
  • The [Bug] JavaScript analysis blocks MCP ping and cancellation during synchronous computation #1462 in-file cancellation test from fix(javascript): yield during per-file projection and graph construction #1525 still passes.
  • npx vitest run src/domain src/application passes (170 files, 2,138 tests).
  • npm run test:focused passes on tests/composition/javascript-applications, tests/acceptance/applications/{javascript,application}*, tests/boundary/mcp/{application,analysisView}* and tests/boundary/cli/analysisView* (20 files, 111 tests).
  • npm run check:fast and npm run docs:check pass. The lint warnings in the touched files are the same set as on main.
  • Not run: Linux, constrained CPUs, or the Notion ASAR.

🤖 Generated with Claude Code

…passes

After #1525 the longest event-loop blocks were single stages on very large
files: semantic analysis of Obsidian's 3.7 MB app.js ran 5.8 s in one piece,
and its object projection 1.8 s.

- analyzeParsedJavaScriptSemanticsSteps yields between the analysis phases
  and between the eight derived collectors; the synchronous function drains
  it, so results are unchanged.
- Per-file analysis yields between open-receiver classification and static
  analysis and drives the semantic steps.
- Semantic node creation, definitions and references, and the object and
  frontier passes yield every 64 items. Node creation keeps source order,
  which the per-file node budget depends on.

On obsidian.asar the longest block falls from 5,355 ms to 907 ms with the
same total time (40.6 s to 39.5 s). Graph IDs and complete result digests
match main on five inputs. Remaining blocks up to about 0.9 s are single
AST traversal passes inside the analyzers.

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.

@kaoru0822-kitauji
kaoru0822-kitauji merged commit ca7ef69 into main Oct 10, 2026
20 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/javascript-semantic-analysis-steps branch October 10, 2026 11:20
N0zoM1z0 pushed a commit that referenced this pull request Oct 10, 2026
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]>
darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…passes (morluto#1542)

* fix(javascript): yield inside semantic analysis and large projection passes

After morluto#1525 the longest event-loop blocks were single stages on very large
files: semantic analysis of Obsidian's 3.7 MB app.js ran 5.8 s in one piece,
and its object projection 1.8 s.

- analyzeParsedJavaScriptSemanticsSteps yields between the analysis phases
  and between the eight derived collectors; the synchronous function drains
  it, so results are unchanged.
- Per-file analysis yields between open-receiver classification and static
  analysis and drives the semantic steps.
- Semantic node creation, definitions and references, and the object and
  frontier passes yield every 64 items. Node creation keeps source order,
  which the per-file node budget depends on.

On obsidian.asar the longest block falls from 5,355 ms to 907 ms with the
same total time (40.6 s to 39.5 s). Graph IDs and complete result digests
match main on five inputs. Remaining blocks up to about 0.9 s are single
AST traversal passes inside the analyzers.

Refs morluto#1462


* refactor(javascript): drop the unused synchronous derived-semantics wrapper


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

2 participants