Repository navigation
perf(resolve): index reference edges by source (#4909) - #4913
Deepjyoti-Sarmah wants to merge 2 commits into
Conversation
The Graphify-Labs#4854 stub-binding pass scanned every edge once per import fact. That made a full rebuild O(imports x edges): 14m7s on a 21k-node TS corpus, versus 26.8s on 0.9.48. Group reference edges by their emitting source file once, then scan only that file's edges per import. The 21k corpus now rebuilds in 25.5s, and the written graph is identical.
|
Thanks for the pull request, @Deepjyoti-Sarmah. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.
Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 not verified).
Formal verification. PR-changed functions: 0/1 verified (0 proven, 0 may-equivalent, 0 distinguished) · 1 not verified (1 unsupported).
Not verified on this run: \_apply\_symbol\_resolution\_facts (unsupported).
Graphify review — findings
Indexes references edges by their resolved source file once, so binding a reference to its imported declaration no longer rescans the whole edge list for every import fact. This takes the pass from O(imports × edges) to linear in graph size on full rebuilds, with the same rewrite behaviour. A new test pins this by counting _js_source_path calls against a linear budget rather than timing anything.
No blocking issues surfaced.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 3353 functions depend on the 172 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
_apply_symbol_resolution_facts()— 6 callers, 12 callees
Verification — 3353 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 1297 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
35 of 480 test file(s) selected (7%) via static blast radius.
tests/test_4909_reference_binding_scale.py— impact, changed-testtests/test_astro_extraction.py— impacttests/test_build.py— impacttests/test_cjs_module_extension.py— impacttests/test_ejs_extractor.py— impacttests/test_ext_tagged_id_clash.py— impacttests/test_extract.py— impacttests/test_forwarding_review_findings.py— impacttests/test_import_extension_resolution.py— impacttests/test_indirect_call_block_scoped_shadow.py— impacttests/test_js_exported_scalar_bindings.py— impacttests/test_js_member_collisions.py— impacttests/test_js_walk_order.py— impacttests/test_language_override_imports.py— impacttests/test_languages.py— impacttests/test_loose_sibling_import_resolution.py— impacttests/test_multilang.py— impacttests/test_package_json_subpath_imports.py— impacttests/test_pascal.py— impacttests/test_pascal_resolution.py— impacttests/test_phantom_external_import.py— impacttests/test_pr10_resolution_overrides.py— impacttests/test_python_import_resolution.py— impacttests/test_python_member_call_language_gate.py— impacttests/test_python_parse_memoization.py— impacttests/test_rationale.py— impacttests/test_resolve_memoization.py— impacttests/test_source_key_memoization.py— impacttests/test_src_layout_import_resolution.py— impacttests/test_svelte_extraction.py— impacttests/test_ts_new_expression_calls.py— impacttests/test_typescript_module_extensions.py— impacttests/test_unmapped_at_alias_resolution.py— impacttests/test_vue_extraction.py— impacttests/test_walk_python_tree_iterative.py— impact
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Formal verification
Could not verify: Could not verify \_apply\_symbol\_resolution\_facts.
The verifier did not have enough to check \_apply\_symbol\_resolution\_facts, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: parameter `facts` is annotated `_SymbolResolutionFacts` — outside the synthesizable primitive/collection set
· 1 more finding(s) on lines outside this diff (see the check run).
|
Landed in v0.9.100, now on PyPI (pip install graphifyy==0.9.100). Reference edges are indexed by source, so JS/TS import resolution no longer re-walks every edge. Thanks for the fix, @Deepjyoti-Sarmah. |
What does this PR do?
Refs #4909.
The current full rebuild is O(imports times edges) in
_apply_symbol_resolution_facts. On a 21k-node TypeScript corpus it takes 14 minutes. The pass added for #4854 loops over every edge for every import so it can rewrite a reference edge from a sourceless stub to the imported declaration.The index is keyed by the same
_js_source_path(...)value the old comparison computed. The per-edge checks stay the same:referencesNo graph schema, cache schema, or manifest field changes. The written graph is identical on the 200-file fixture.
This does not close the rest of #4909.
_collect_js_symbol_resolution_factsstill re-parses every JS/TS tree, and the original 0.9.48 profile has other costs. This removes the current regression that makes a full rebuild worse than the reported version.Type of change
Evidence
Before: current
v8ata0946f96.After: branch
fix/4909-reference-index.Speedup on the 21k corpus: about 34.8x.
Scaling:
The before path is quadratic. The after path is close to linear.
Failing test before the fix:
After:
The test counts
_js_source_pathcalls and requires a linear budget. It does not measure wall time, so it will not flake on a busy CI machine.Graph equality on the 200-file corpus:
Verification & Invariants
The invariant: the cost of reference binding scales with nodes, edges, and imports, not with imports times edges. A per-import full scan fails the new test.
Limitation: the index holds reference edges grouped by source file for the duration of this pass. That is one list per file, not a second graph. Memory is proportional to the reference edge count.
How was this tested?
Results:
Merge Danger
Door: Two-way.
The change is local to one resolution pass and can be reverted without a graph migration. No schema bump and no cache invalidation.
Blast Radius: JS/TS reference binding.
The main risk is a subtle change in which edges are rewritten. The index uses the same source path and the same checks as the old loop. The 200-file graph comparison found identical nodes, fields, and edges, and all #4854 tests pass. A revert restores the old behavior and the old cost.
Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. No source fragments changed.