Repository navigation
Conversation
suggest_questions runs nx.betweenness_centrality to pick the top 3 bridge nodes. On a graph over 1000 nodes it samples 100 sources, but each search still reaches nearly the whole graph, with the search state in dicts keyed by node id. On Guava's 84k-node graph that was 18.2s of a 51.9s one-file update. _betweenness_centrality numbers the nodes once and keeps the same state in lists, resetting only the entries a source reached. It follows networkx's search order, summation order and rescale, so the scores match networkx 3.5 and later bit for bit. The step drops to 4.6s on Guava, and from 7.8s to 2.3s on Django. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the pull request, @Max17190. 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.11 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify code review 
Review completed · 5eac2f3e8817
Tip
Merge confidence: 5/5 · Looks safe to merge · 🟠 High impact
No issues reported
1 not re-checked
The added tests compare the helper’s centrality scores with NetworkX across small, sampled, directed, and disconnected graphs.
Full summary
The added tests compare the helper’s centrality scores with NetworkX across small, sampled, directed, and disconnected graphs. They also include a graph larger than 1,000 nodes to cover the sampling size used by suggest_questions.
Code graph and static checks · 1101 functions depend on this change
Impact & health
Impact — 1101 functions depend on the 138 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
suggest_questions()— 22 callers, 6 callees
Formal checks — 1101 functions this change can affect weren't formally checked in this review. Formal checks are informational only.
Gate & verification
✅ PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 729 function(s) in the blast radius were not formally verified this run
Test selection
61 of 593 test file(s) selected (10%) via static blast radius.
tests/test_analyze.py— impact, changed-testtests/test_atomic_canvas_export.py— impacttests/test_atomic_writes.py— impacttests/test_build.py— impacttests/test_build_merge_ghost_fold_4955.py— impacttests/test_build_merge_hyperedges_and_prune.py— impacttests/test_carried_hyperedge_remap.py— impacttests/test_chunking.py— impacttests/test_cli_export.py— impacttests/test_community_labels_skill.py— impacttests/test_compact_graph_json.py— impacttests/test_confidence.py— impacttests/test_confidence_score_output.py— impacttests/test_cpp_forward_declarations.py— impacttests/test_cpp_member_declaration_identity.py— impacttests/test_cross_extension_reexport_self_cycle.py— impacttests/test_csharp_method_owner_labels.py— impacttests/test_dedup_shrink_refuses_force_write.py— impacttests/test_export.py— impacttests/test_export_control_characters.py— impacttests/test_export_direction.py— impacttests/test_export_idempotent_writes.py— impacttests/test_export_path_length.py— impacttests/test_extract.py— impacttests/test_extract_memory_release.py— impacttests/test_falkordb_integration.py— impacttests/test_go_qualified_resolution.py— impacttests/test_god_nodes_exclude_hubs.py— impacttests/test_graphdb_push_indexes.py— impacttests/test_html_script_breakout.py— impacttests/test_html_theme.py— impacttests/test_hyperedge_roundtrip.py— impacttests/test_hypergraph.py— impacttests/test_import_cycles_shortest_first.py— impacttests/test_js_import_resolution.py— impacttests/test_js_member_collisions.py— impacttests/test_labeling.py— impacttests/test_lost_saved_semantic_nodes.py— impacttests/test_obsidian_dangling_member.py— impacttests/test_obsidian_filename_cap.py— impacttests/test_obsidian_unicode_tags.py— impacttests/test_obsidian_vault_migration.py— impacttests/test_pipeline.py— impacttests/test_python_import_resolution.py— impacttests/test_reflect.py— impacttests/test_report.py— impacttests/test_report_gap_thresholds.py— impacttests/test_semantic_origin_stamp.py— impacttests/test_semantic_similarity.py— impacttests/test_serve.py— impact- … and 11 more
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.
Every flagged function
suggest_questions()ingraphify/analyze.py:558· 22 callers, 6 callees: fans out to 6 callees (efferent coupling); 22 callers depend on it (afferent coupling)
networkx 3.4, which pyproject.toml still allows, rescales sampled betweenness scores differently from 3.5 and later. The fast path follows 3.5, so on 3.4 a report could print a different bridge score: 0.108 instead of 0.107 on axum. On networkx before 3.5, _betweenness_centrality now returns networkx's own result, so the report matches v8 on every supported version, and the tests no longer skip the sampled cases there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Why
suggest_questionsrunsnx.betweenness_centralityto pick the top 3 bridge nodes for the report. Once a graph has more than 1000 nodes it samples 100 sources, but each search still reaches 96 to 100% of the graph, and networkx keeps that search state in dicts keyed by node id. Every full build runs this step, and so does everygraphify updatethat finds a changed file. On Guava it takes a third of a one-file update.graphify updatesuggest_questionson v8Median of 3 runs on an Apple M5 with Python 3.13 and networkx 3.7. In one full build each, the step went from 6.4s to 2.7s on Django and from 14.1s to 4.7s on Guava.
Summary
_betweenness_centralitynumbers the nodes once and keeps distances, path counts and predecessor lists in lists. After each source it resets only the entries that source reached.nx.betweenness_centrality(G, k=k, seed=42)bit for bit on networkx 3.5 and later. The lockfile has 3.6.1 and 3.7.pyproject.tomlstill allows networkx 3.4, which rescaled sampled scores differently. There it returns networkx's own result, so the report matches v8 on every supported networkx. Without that, axum's report on 3.4.2 printed one bridge score as 0.108 instead of 0.107.Test plan
The new tests compare every score and the key order with networkx. They cover empty, one-node, path, star, cycle and complete graphs, random directed and undirected graphs with self-loops and isolated nodes, and sampled runs up to k=100 on 1500 nodes. On networkx 3.4.2 the three sampled cases fail without the 3.4 fallback.
End to end on gin, ripgrep, axum, clap, excalidraw, Django and Guava, I ran a full build, then a one-file edit and
graphify update, on v8 and on this branch at the same path.graph.json,graph.htmlandGRAPH_REPORT.mdcame out byte-identical every time.manifest.jsonand the build state differ only in timestamps. On networkx 3.4.2, the suggested questions match v8 on all seven graphs.