[PR #1542] [MERGED] fix(javascript): yield inside semantic analysis and large projection passes #2957

Closed
opened 2026-10-17 21:12:15 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/1542
Author: @kaoru0822-kitauji
Created: 10/10/2026
Status: ✅ Merged
Merged: 10/10/2026
Merged by: @kaoru0822-kitauji

Base: main ← Head: fix/javascript-semantic-analysis-steps


📝 Commits (2)

  • 6af127c fix(javascript): yield inside semantic analysis and large projection passes
  • cd35d51 refactor(javascript): drop the unused synchronous derived-semantics wrapper

📊 Changes

7 files changed (+150 additions, -62 deletions)

View changed files

📝 src/application/javascript/JavaScriptArtifactAnalysis.ts (+3 -2)
📝 src/application/javascript/JavaScriptSemanticGraphBuilder.ts (+64 -46)
📝 src/application/javascript/JavaScriptSemanticGraphFlowProjection.ts (+5 -4)
📝 src/application/javascript/JavaScriptSemanticGraphObjectProjection.ts (+5 -4)
📝 src/domain/javascript/javascriptSemanticAnalysis.ts (+25 -3)
➕ src/domain/javascript/javascriptSemanticAnalysisSteps.test.ts (+34 -0)
📝 src/domain/javascript/javascriptSemanticDerivedAnalysis.ts (+14 -3)

📄 Description

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:

  • the #1462 1,200-function fixture;
  • Obsidian app.asar and obsidian.asar (23 MB, 36 JS files);
  • Tabby app.asar;
  • the #1495 box fixture.

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 #1462 in-file cancellation test from #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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/1542 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/10/2026 **Status:** ✅ Merged **Merged:** 10/10/2026 **Merged by:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Base:** `main` ← **Head:** `fix/javascript-semantic-analysis-steps` --- ### 📝 Commits (2) - [`6af127c`](https://github.com/morluto/rea/commit/6af127c63a4238f82b910527596397078d4865cb) fix(javascript): yield inside semantic analysis and large projection passes - [`cd35d51`](https://github.com/morluto/rea/commit/cd35d51b76b6decc9e8c6e27526f6bd26ae9c552) refactor(javascript): drop the unused synchronous derived-semantics wrapper ### 📊 Changes **7 files changed** (+150 additions, -62 deletions) <details> <summary>View changed files</summary> 📝 `src/application/javascript/JavaScriptArtifactAnalysis.ts` (+3 -2) 📝 `src/application/javascript/JavaScriptSemanticGraphBuilder.ts` (+64 -46) 📝 `src/application/javascript/JavaScriptSemanticGraphFlowProjection.ts` (+5 -4) 📝 `src/application/javascript/JavaScriptSemanticGraphObjectProjection.ts` (+5 -4) 📝 `src/domain/javascript/javascriptSemanticAnalysis.ts` (+25 -3) ➕ `src/domain/javascript/javascriptSemanticAnalysisSteps.test.ts` (+34 -0) 📝 `src/domain/javascript/javascriptSemanticDerivedAnalysis.ts` (+14 -3) </details> ### 📄 Description 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: - the #1462 1,200-function fixture; - Obsidian `app.asar` and `obsidian.asar` (23 MB, 36 JS files); - Tabby `app.asar`; - the #1495 box fixture. ## 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 #1462 in-file cancellation test from #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](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-17 21:12:15 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#2957
No description provided.