Repository navigation
fix(javascript): yield during per-file projection and graph construction - #1525
Conversation
analyze_javascript_application ran several long phases with no event-loop turn, so MCP ping and cancellation waited: each file's parse, analysis and semantic projection; building every application node and relationship before the application graph's first sealing step; and whole-graph schema parses inside both immutable graph factories. - Each file runs as steps (parse, static analysis, semantic analysis, then each projection pass), driven by the existing time-sliced checkpoint. - Application graph input construction yields between phases, per module link and per file of findings. - The pipeline transfers its privately built graph inputs to new sealing steps that validate the graph's own fields synchronously and elements, content checks and the digest in steps. The public copying factories keep their synchronous capture. Results are unchanged: graph IDs and the complete result digest match main on five inputs including Obsidian's 23 MB obsidian.asar. On the issue's 1,200-function fixture the longest event-loop block falls from about 290 ms to 90 ms, and ping after abort from up to 286 ms to at most 56 ms. On obsidian.asar it falls from 10.9 s to 5.4 s; the rest is one analyzer stage of a single very large file. 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. |
|
The red CI here doesn't come from this PR. Shard 3/4 fails only on the #1495 wall-time test from #1517 (3.6 s against a 2 s bound under v8 coverage), and |
|
Independent Linux x64 review of The real ASAR (SHA-256 On the issue's exact 1,200-function source SHA 37 focused tests across application cancellation/service, graph validation/ownership, and compiled CLI/stdio-MCP return/iteration workflows passed. Strict typecheck/lint pass. A final public retained-view and #1526 regression pass has also been run. No Hopper/Ghidra claim or lane applies to this JavaScript change. The CI shard failure is the existing main #1517 timing assertion, observed at 3,610.3 ms versus its 2,000 ms threshold ( |
…passes (#1542) * fix(javascript): yield inside semantic analysis and large projection 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]> * refactor(javascript): drop the unused synchronous derived-semantics wrapper Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…ion (morluto#1525) analyze_javascript_application ran several long phases with no event-loop turn, so MCP ping and cancellation waited: each file's parse, analysis and semantic projection; building every application node and relationship before the application graph's first sealing step; and whole-graph schema parses inside both immutable graph factories. - Each file runs as steps (parse, static analysis, semantic analysis, then each projection pass), driven by the existing time-sliced checkpoint. - Application graph input construction yields between phases, per module link and per file of findings. - The pipeline transfers its privately built graph inputs to new sealing steps that validate the graph's own fields synchronously and elements, content checks and the digest in steps. The public copying factories keep their synchronous capture. Results are unchanged: graph IDs and the complete result digest match main on five inputs including Obsidian's 23 MB obsidian.asar. On the issue's 1,200-function fixture the longest event-loop block falls from about 290 ms to 90 ms, and ping after abort from up to 286 ms to at most 56 ms. On obsidian.asar it falls from 10.9 s to 5.4 s; the rest is one analyzer stage of a single very large file. Refs morluto#1462 Co-authored-by: N0zoM1z0 <[email protected]>
…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 ---------
|
TL;DR: This merged while I tested, and the squash I tested main Ping wait after the abort at 200 ms, in ms. Each cell is the median of 3 runs.
Longest ping wait in one full app run, in seconds. Each cell shows two runs, with a ping every 250 ms.
Where the event loop stops, on Node 24, longest block in ms. A timer in the server logs each gap, and a CPU profile shows what runs in it.
Main and #1525 gave the same app graph ID, semantic graph ID and Evidence SHA-256 on all four targets. All 126 cancels worked on both trees, and both changed test files pass on Node 22, 24 and 26. The IDs and details are in the folds below. Not run
Thanks, kaoru0822-kitauji, for the step split and for the test that cancels inside one large file. More notes on the tables
Same results, cancels and testsMain and #1525 gave the same results, byte for byte:
Abort sweep, Node 24, 1,200 functionsPing wait after the abort, ms, median [min–max] of 3:
Raw numbersAbort at 200 ms, ms, median [min–max] of 3:
"Server stop" is REA's own tool-done log line, in ms from the call. Full analysis time, s, as REA logs it, two runs:
How I measured
Commandsgit -C rea.git archive b88d8f859b031763f708c8a018ddd50c0e04dfe6 | tar -x -C pr
cd pr && npm ci && npm run build
# abort runs, and the sweep with --cancel-ms 50 … 600
node client.mjs --root pr --fixture f1200 --mode at-offset --cancel-ms 200 \
--ping-ms 0 --retained-check --next-small f3 \
--server-node-args --max-old-space-size=3072
# app runs
node client.mjs --root pr --fixture app.asar --format asar --mode none \
--ping-ms 250 --ping-timeout-ms 45000 --call-timeout-ms 210000 \
--export-evidence "$TMPDIR/ev.json" --next-small f3 \
--server-node-args --max-old-space-size=4096
# identity
node scripts/rea.mjs analyze-javascript-application <input> \
--artifact-format <directory|asar> --json | sha256sum
# tests
npm run test:focused -- \
src/application/javascript/JavaScriptApplicationCancellation.test.ts \
src/domain/javascript/javascriptApplicationAnalysisSteps.test.ts
npm run check:fastTest setup
🤖 Generated with Claude Code (Opus 5.5) 🦊 |
Refs #1462 (T2 responsiveness under #1065). This removes the long event-loop blocks after the per-file stage and splits the per-file stage itself. A residual remains and is described below.
Where the pauses were
Measured in-process with a 1 ms interval timer recording event-loop gaps, plus the issue's SDK stdio probe. On the issue's 1,200-function fixture (SHA-256
1c6cafca…7711) onmain:index.js(parse 13, receivers 11, static 16, semantic 71, projection ~130 ms)buildImmutableJavaScriptArtifactGraphSteps: alladd*phases plus the factory's synchronous parse, content check and digest run before the first stepfinishImmutableSteps: the semantic factory's synchronous whole-graph schema parse and normalizationChange
analyzeAndProjectJavaScriptArtifactFiles): parse, receivers/static analysis, semantic analysis and each of the ~17 semantic projection passes are now steps. They are driven by the existing time-slicedcompleteJavaScriptAnalysisSteps(8 ms slices, abort checks).projectFileStepsis new onJavaScriptSemanticGraphProjection; the synchronousprojectFileandanalyzeJavaScriptArtifactFilesdrain the same steps, so their results are unchanged.buildImmutableJavaScriptArtifactGraphStepsis a generator. It yields between phases, per module link (addJavaScriptModuleRelationshipsSteps) and per file of findings (addJavaScriptStaticFindingsSteps).buildJavaScriptArtifactGraphdrains it synchronously.sealTransferredJavaScriptApplicationGraphStepsandsealTransferredJavaScriptSemanticGraphStepsare for inputs the caller transfers, meaning it neither retains nor mutates them. They validate the graph's own fields and container constraints (such asnodes.min(1)) synchronously. Elements are then validated (and cloned) in steps through the newsrc/domain/zodCollectionSteps.ts, followed by the content checks (checkGraphContentSteps, now stepwise) and the canonical digest. Only the analysis pipeline uses them, because it builds those inputs privately. It now passes a copy offingerprints, which it clears afterwards.createImmutable…GraphStepsfactories keep their synchronous deep capture. That capture is pinned bycaptures nested input before yielding…, which still passes. A content-check failure in the transfer path re-runs the content schema, so the error is the exactZodErrorthe copying path reports.Results are identical
reconstructJavaScriptArtifactonmainand on this branch gives the same application graph ID, semantic graph ID and SHA-256 of the complete serialized result for:app.asarand the 23 MBobsidian.asar;app.asar;Measured effect
1,200-function fixture, in-process: the longest event-loop block goes from about 290 ms to about 90 ms.
The issue's MCP probe (warmed SDK stdio client, abort, then ping), swept over abort times of 50–600 ms on an M-series Mac:
The client wait ended within about 2 ms of each abort, as before.
Obsidian
obsidian.asar(36 files), full in-process analysis:app.jsanalysis plus projection)The post-file graph phases no longer appear among the longest blocks.
Residual (not fixed here)
The remaining multi-second blocks are single analyzer stages on very large single files:
analyzeParsedJavaScriptSemanticsor static analysis of Obsidian's 3.7 MBapp.js(about 5.4 s) andlib/mermaid.min.js(about 4.4 s). Splitting those needs either steps inside the domain analyzers or an owned execution boundary such as a worker. Both are larger design changes, so I left #1462 open.Verification
JavaScriptApplicationCancellation.test.ts([Bug] JavaScript analysis blocks MCP ping and cancellation during synchronous computation #1462) aborts three event-loop turns after the one large file starts, and checks that cancellation lands beforebuild_javascript_application_graph. Onmainit fails because the phase list includes that phase.javascriptApplicationAnalysisSteps.test.ts: the transfer factories seal graphs equal to the copying factories, and those graphs are validated and immutable. For a malformed semantic node and a stale application node ID, they report the same issues as the whole-graph parse.npx vitest run src/domain src/applicationpasses (169 files, 2,131 tests).npm run test:focusedpasses ontests/composition/javascript-applications,tests/acceptance/applications/{javascript,application}*,tests/boundary/mcp/{application,analysisView}*andtests/boundary/cli/analysisView*(20 files, 111 tests).npm run check:fastandnpm run docs:checkpass. One new non-blocking warning:max-linesonjavascriptApplicationGraph.ts, where the ownershipWeakSetand the new sealing steps must share a module.JavaScriptSemanticGraphBuilder.tsandjavascriptSemanticGraph.tsalready carrymax-lineswarnings onmain.🤖 Generated with Claude Code