[Bug]: update never finishes on large repos: _collision_aware scans every node id for every use (uses x nodes)
Pre-flight checks
- [x] I have checked the Troubleshooting section in the README
What happened?
graphify update never finishes on large repos. After per-file extraction it sits in one line of _apply_symbol_resolution_facts (graphify/extractors/resolution.py, the nested _collision_aware added in #4997):
if not any(other.startswith(source_id + "_") for other in owned):
That runs over every node id for every resolved use fact, and on a hit nodes is scanned a second time. So the cost is uses x nodes.
| repo | cold update |
time in _apply_symbol_resolution_facts |
|---|---|---|
| django | 116.8 s | 11.3 s |
| pandas | 123.6 s | 26.2 s |
| sympy | 1,324.6 s | 1,189.0 s |
| vscode 1.145.2 (17,661 code files) | killed at a 60-minute cap, no graph.json written | py-spy at 30 min: resolution.py:1886, this startswith generator |
This is a different loop from #4905 / #4915 (fixed by #4907): those were JS/TS imports x edges in the stub-rebinding pass. This one is in the caller pass.
Steps to reproduce
git clone --depth 1 https://github.com/sympy/sympy && cd sympygraphify update .- After extraction,
py-spy dump --pid <pid>shows it inresolution.py_collision_aware, for about 20 minutes.
Synthetic version (times the function alone, growing node count):
nodes=2000: 0.31s 4000: 1.28s 8000: 7.50s (grows about n^2)
Error output or graph output
No error. update runs until it is killed; on vscode no graph.json is written.
Graphify version
0.9.105 (v8 at 5eedffa8)
Operating System
Windows (also seen on Linux)
Python Version
3.12
Installation Method
uv tool install (recommended)
Additional context
Found while profiling large repos. Fix idea: group the node ids once by their plain id (a salted id is <plain>_<6 hex>, the _underscore_salted_nid rule) and look up only that group per use. Same answers, uses + nodes.
Thanks for opening this issue, @rohit-jsfreaky. A maintainer will take a look soon.
If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.
To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.
Fixed in 0.9.106 (now on PyPI) via #5111: _collision_aware indexes salted sibling ids once instead of rescanning all nodes per use, with byte-identical graph output.