mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-09-15 23:32:49 +00:00
Introduces `WorkspaceResolutionIndex` — a precomputed bundle of lookup tables built ONCE per resolution run, after `populateOwners` and after finalize, before any pass that needs to find members, exported defs, or class scopes by id. What it replaces (all are pre-existing O(N×D) linear scans of parsedFiles, called inside the receiver-bound MRO chain): - `findOwnedMember(ownerId, name, parsedFiles)` → `Map.get` via `index.memberByOwner.get(ownerId)?.get(name)`. Was the worst offender — receiver-bound dispatcher calls this O(sites × MRO depth) times. - `findExportedDef(filePath, name, parsedFiles)` → `Map.get` via `index.defsByFileAndName`. Hot for namespace-receiver case. - `findExportedDefByName` workspace-wide fallback scan → `Map.get` via `index.callablesBySimpleName`. - `classScopeByDefId` (rebuilt inside `emitReceiverBoundCalls` on every invocation) — moved to one-shot build during finalize, read from `index.classScopeByDefId` everywhere. - `moduleScopeByFile` (rebuilt inside `propagateImportedReturnTypes` on every invocation) — read from `index.moduleScopeByFile`. Findings from a synthetic 100-file Python workload (60 model files each defining 5 classes × 3 methods + 40 user files calling them heavily): scope-resolution wall time: 764ms → 710ms (median, 5 iters) That's a ~7% in-layer win. The smaller-than-expected gain was informative: profiling the synthetic workload shows scope-resolution breakdown is `extract=62% resolve=30% emit=4%`; the index touched the 4% slice (emit + walker calls inside it). Larger O(D) per owner classes will benefit more. Profiling the FULL pipeline (49 fixtures × 3 iters) shows scope-resolution accounts for ~1% of pipeline wall time — the remaining 99% is parse (tree-sitter), heritage, ORM, MRO, processes, and DB writes. So further optimization of this specific layer has marginal pipeline impact; the next-biggest wins live in those phases. Documented as the "double-parse" finding in the audit (captures.ts re-parses each Python file even though the parse phase already produced a tree-sitter Tree) — that's a separate plumbing project across phase boundaries. Bonus: opt-in PROF_SCOPE_RESOLUTION=1 env var prints a per-phase ms breakdown to stderr, so future perf work can measure without extra code changes. Verification: - REGISTRY_PRIMARY_PYTHON=0 (legacy): 191/191. - REGISTRY_PRIMARY_PYTHON=1 (registry): 191/191. - tsc --noEmit clean. |
||
|---|---|---|
| .. | ||
| bench-scope-resolution.ts | ||
| build-tree-sitter-proto.cjs | ||
| build.js | ||
| ci-list-migrated-languages.ts | ||
| patch-tree-sitter-swift.cjs | ||