Repository navigation
perf(javascript): queue binding initializers once per ambient alias query - #10681
Conversation
…uery Ambient-write indexing resolves every escaped call argument and method receiver through the ambient path resolver. Within one query, each identifier read it reached requeued every selected initializer of its binding, although an initializer already expanded with the same projection only revisits its expanded root. Where locals copy each other inside loops, as in wasm2js output, one query reaches hundreds of reads of bindings with hundreds of initializers, so the work per query grew quadratically. On pdf.js's openjpeg_nowasm_fallback.js, ambient indexing alone took 137 s in-process. Reads that select the same initializers for the same projection now share one queue entry, whose remaining items are taken in the original last-in-first-out order. Items already taken are not requeued. Every expansion that is not a revisit happens in the same order as before, so resolutions are unchanged. Validation: - New work-count regression: during the single escape query of a looping a=b/b=a cycle, reads of the copied values are 1087 and 2175 for 32 and 64 copies (base: 5551 and 20319). The test fails on the base revision. - npm run test:local over src/domain/javascript (187 files, 5817 tests) and src/application/javascript (31 files, 695 tests): pass. - Ambient write and escape effects, retained global call receivers and escaping reference stores are byte-identical before and after on openjpeg_nowasm_fallback.js. Static facts and member-mutation state are byte-identical on 12 other bundles. - openjpeg_nowasm_fallback.js, ambient indexing in-process from the built dist, one cold run each on a 4 vCPU host: 137.4 s -> 26.4 s; process CPU 154.0 s -> 31.0 s; peak RSS 863 MB -> 388 MB. - npm run check:fast: pass. The CLI still does not complete that file: its worker now exhausts the 1024 MiB heap in member-mutation traversal after 246 s, rather than reaching the 300 s per-source deadline. Refs morluto#2498
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] This PR appears safe to merge; no blocking issues were found. SummaryThis PR queues each binding's selected initializers once per projection within an ambient alias query.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Read a binding] --> B[Select initializers at this read]
B --> C{Binding and projection already queued?}
C -->|No| D[Build initializer items]
C -->|Yes| E[Reuse shared cursor]
D --> E
E --> F[Take last remaining item]
F --> G{Root needs expansion?}
G -->|Yes| H[Follow references and retain paths]
G -->|No| I[Skip repeated work]
Reviews (2) · Last reviewed commit: "Merge morluto/rea main into ambient-writ..." · Reviewed by Greptile |
# Conflicts: # src/domain/javascript/javascriptSemanticAmbientWrites.ts
Adds morluto/rea#10681 to the REA list.
Summary
Refs #2498 (partial). In
createAmbientPathResolver(src/domain/javascript/javascriptSemanticAmbientWrites.ts), every identifier read that one query reached requeued all of its binding's initializers. In wasm2js output, locals copy each other inside loops, so one escape query reaches hundreds of reads of bindings with up to 775 initializers. Work per query therefore grew quadratically. Before this change, the first 8,000 escape queries made 150 M queue pops for 5.4 M unique items.Reads that select the same initializers for the same projection now share one queue entry. Its items are taken in the original last-in-first-out order, and items already taken are not requeued. Every expansion that does real work runs in the same order as before, so results are unchanged.
Evidence and regression coverage
javascriptSemanticAmbientWrites.test.ts: a loopinga=b; b=acycle with one escape, counting reads of the copied values.openjpeg_nowasm_fallback.js(the sha256 matches the issue). One cold run per configuration on a 4-vCPU host; warm runs were not measured.markEscaped→markValue, the original [Perf] Semantic member-mutation traversal takes 84 s and 1.2 GB on pdf.js's 462 KB openjpeg_nowasm_fallback.js #2498 hotspot) now dominates, at 72% of a 150 s profile. analyze_javascript_application hangs at parse_javascript_source on 664KB single-line ESM UMD (@castleio/castle-js) #6311 is a different mechanism (the store fixpoint) and does not improve. The escape loop does not yield, so in-process cancellation can wait about 26 s on this file.Validation performed
npm run test:localoversrc/domain/javascript(187 files, 5,817 tests) andsrc/application/javascript(31 files): passed.npm run build:cachedandnpm run check:fast: passed.Author readiness
Human owner: @Davmunrey
Before merge
type(scope): outcome.