Repository navigation
perf(javascript): share one lexical index between static and semantic analysis - #14148
Conversation
… analysis The static and semantic phases each built a private semantic state for the same parsed program, so definitions, ambient writes and member-mutation facts were derived twice per file. Sharing the state requires separating what it holds. Index facts are shared. Memoized query results are declared through one owner so a new consumer or index step starts without them. Observations (resource limits and returned-reference widenings) are recorded per derivation: index steps record into the index's own log and each consumer starts from that log, so the semantic phase reports exactly what a private index would have. The worker builds one index per parsed file and the semantic phase continues from it when its resolution mode matches the static phase. Refs #14147
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. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
[Medium impact] The PR appears safe to merge; no actionable defects remain from this review. SummaryThe worker reuses one lexical index between static and semantic analysis when their resolution modes match.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
P[Parsed program] --> I[Build lexical index]
I --> S[Static analysis]
S --> M{Semantic mode is import?}
M -->|Yes| R[Check and consume shared index]
M -->|No| N[Build private semantic index]
R --> C[Reset query memos and seed index observations]
C --> A[Semantic analysis]
N --> A
Reviews (2) · Last reviewed commit: "fix(javascript): let a shared lexical in..." · Reviewed by Greptile |
|
Integration note with #14153. See the note there: the two merge cleanly but need a one-line adjustment to compile together, because this PR moves the limit sets under |
…c phase The semantic phase appends its module links and callable facts to the state it continues from, so a second phase from the same index reported each import link twice. Admission is now consumed by the first phase and a second is rejected like any other index that does not match.
Summary
Refs #14147 (step 1 of 2; traversal fusion is a follow-up).
The JavaScript analysis worker ran its static and semantic phases on two private semantic states for the same parsed program. Each built definitions, ambient writes and member-mutation facts separately, which was about 22% of analysis time on
@babel/parser(profile in #14147). This PR builds one lexical index per parsed file and has the semantic phase continue from it.Design
Sharing the state object alone is wrong. A naive prototype changed semantic output on
openpgp.min.js, where static-phase queries leaked two returned-reference widenings into the semantic IR. The state held three kinds of data with different owners, and this PR separates them (javascriptSemanticConsumer.ts):WeakMaps keyed by the state)semanticConsumerMemo(), so a new consumer or index step starts without themvalueResourceLimits,getterResourceLimits,returnedReferenceWidenings)state.observations; index steps record intostate.indexObservations, and each consumer starts from that logsemanticIndexStepwraps the three index steps (definitions, ambient writes, member-mutation facts). A step reads no consumer memo and records into the index's log, so its facts do not depend on which consumer requested it or what that consumer queried first.analyzeParsedJavaScriptSemanticsStepsaccepts alexicalIndexand fails closed. The index must come fromindexJavaScriptBindingsWithReceiversStepswith no host context and the same program, resolution mode, precision and allowance; anything else throwsTypeError."import", the mode the static phase indexes under..cjs/.ctsand.ts/.tsxfiles keep private states, because their mode changes the definitions themselves.Validation
node_modules, plus repo fixtures. For each file I compared SHA-256 of the static facts and of the semantic IR againstmain. 0 differences with private indexes (the refactor changes nothing by itself) and 0 differences with the shared index (1,352 files took the shared path; the rest have another resolution mode). 64 files hit resource limits and 185 report widenings, so the observation paths are exercised. Runningmaintwice gave identical hashes. The harness is a local script, not part of this PR.javascriptSemanticSharedIndex.test.ts): shared-index results equal private-index results; an earlier consumer's observations stay out of the semantic phase; index-step observations reach the semantic phase; mismatched indexes are rejected. Working control: the isolation test fails with the consumer handoff disabled.src/domain/javascript/*.test.tsandsrc/javascript/analysis/*.test.ts: 209 files, 6,235 tests passed.javascriptReturnedReferencesandjavascriptAnalysisLimitsacceptance tests passed.oxfmt --check;check:fast(typecheck, lint, architecture guards).Measurement
In-process, both phases, on a 360-file (10.7 MB) sample of the corpus; two sequential runs each on macOS arm64, Node 24.22.1:
mainThat is 9–16% less wall time on this sample. Not measured: CPU time, peak memory, and the end-to-end worker. Agent tokens are unaffected, since outputs are identical.
Remaining
"import"still index twice; sharing them needs the static phase to index under the file's own mode, which may change static facts and needs its own review.