Repository navigation
Description
Summary
A full code rebuild (_rebuild_code(Path('.')), the path graphify watch and graphify update take) on a 21.5k-node TypeScript repo takes 105 s when nothing has changed and every file is in the extraction cache. Parsing is 5 s of that. The rest is Python-side path and string work in four places, each of which recomputes the same values per node or per file.
Environment
- graphifyy 0.9.48, CPython 3.12.13 (uv), macOS 15 on Apple Silicon (arm64)
- repo: a pnpm monorepo, 2,624 scanned files, mostly TypeScript; graph.json 21.5k nodes after build
- run:
python -c "from graphify.watch import _rebuild_code; from pathlib import Path; _rebuild_code(Path('.'))"under cProfile, second run with a warm cache and no file changed
Profile (cumulative, warm cache, nothing changed)
total 104.97 s
extract.extract 71.4 s
resolution._augment_symbol_resolution_edges 35.8 s
resolution._collect_js_symbol_resolution_facts 28.8 s (_walk_js_tree: 25.6M calls, 14.9 s)
resolution._apply_symbol_resolution_facts 6.7 s
resolution._disambiguate_colliding_node_ids 22.2 s
resolution._source_key (143,032 calls) 21.8 s
extract._extract_parallel (the parsing, all cached) 5.6 s
detect.detect 17.0 s
detect._is_ignored (2,624 calls, 6 ms each) 15.7 s
detect._eval (11,016 calls) 15.4 s
watch._reconcile_existing_graph 9.8 s
watch.identity / absolute_identity (150k calls each) 5.4 s
build.build_from_json 3.2 s
Clustering did not run in this profile (same topology, early exit); on a run where it does, cluster.cluster is about 5 s.
What the numbers say
_disambiguate_colliding_node_idscalls_source_keyonce per node (143k calls for 21.5k nodes, so several times per node) and each call does path normalisation. Memoising_source_keyper node id, or computing it once per file, would take this from 22 s to well under a second._collect_js_symbol_resolution_factswalks every JS/TS syntax tree again (25.6M_walk_js_treecalls) even though the per-file extraction is cached. The facts it collects depend only on the file, so they could be cached beside the per-file extraction result and only recomputed for files whose hash changed._is_ignoredcosts 6 ms per file:_evalis called 4 times per file and the ignore patterns look like they are re-evaluated (and the file path re-split) on every call. Compiling the pattern set once per run, and short-circuiting on directory prefixes, would make detection a fraction of a second for 2.6k files._reconcile_existing_graphresolvesidentity/absolute_identity150k times for what are 21.5k distinct paths; a dict from node id to normalised path would do it once.
Together these four are about 95 of the 105 seconds. None of them depends on the size of the change, so the whole cost is paid on every rebuild, which is what makes a watch on an active repo expensive (we measured 98 rebuilds in a day, about three hours of CPU, on a merge-triggered schedule).
I am happy to run the same profile on a branch or share the full cProfile dump if useful.
Activity
github-actions commentedon Oct 31, 2026
Thanks for opening this issue, @danieltamas. 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.
Deepjyoti-Sarmah commentedon Oct 31, 2026
I reproduced the shape on a synthetic 21k-node TS repo.
On 0.9.48: 26.8 s wall, 53.5 s under cProfile. The same passes dominate:
augment 14.5 s, reconcile 12.8 s, build 7.3 s, collect 9.3 s,
disambiguate 3.5 s.
On current v8: an unchanged rebuild returns in 0.57 s because of the #4740
gate. A rebuild after any change is 14 m 7 s on the same corpus. The cost is
an O(imports * edges) loop in _apply_symbol_resolution_facts added in #4854.
Indexing reference edges by source path drops it to 27.0 s.
So three of the four original items are improved on current, but the current
full rebuild is much worse. I will open a PR for the edge index.
test(resolve): pin linear reference binding for #4909
perf(resolve): index reference edges by source for #4909
safishamsi commentedon Nov 1, 2026
Fixed in v0.9.100 via #4913 (pip install graphifyy==0.9.100). Reference edges are indexed by source, so import resolution no longer re-walks every edge. Thanks for the report, @danieltamas.