Repository navigation
Conversation
suggest_questions computes betweenness with 100 sampled sources on every full rebuild and every topology-changing update. The scalar Brandes loop spends most of that time in Python bookkeeping per neighbor entry: about 45s on a 470k node graph and 67s on a 315k node graph. Run each source's search one breadth-first level at a time over a CSR copy of the adjacency instead. Every float sum is still taken in the order networkx takes it, so the scores stay bit-identical: the next level comes out in queue order by keeping each node's first appearance in the level's expansion, path counts are summed with np.bincount in expansion order, and dependencies are summed per predecessor in reverse queue order of the successors after a radix sort of the arcs. Scores are added per source in source order and rescaled exactly as before. numpy only pays off when levels are wide. Each level costs a few dozen numpy calls, so chains, deep trees and tiny graphs would get slower; once the levels seen average fewer than 128 neighbor entries, the remaining sources go through the unchanged scalar loop, which adds into the same scores. Fixes Graphify-Labs#5667 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
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 review 
No issues reported · High impact
The betweenness calculation now uses a NumPy breadth-first-level path for wider searches and keeps the scalar path for searches that become narrow.
Code graph · 1217 functions depend on this change
- 68 of 665 test files are affected by this change.
- Gate, test list and every flagged function: in the Graphify check.
Reviewed f7e883e
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
suggest_questionscomputes sampled betweenness on every rebuild. The scalar loop takes 45s on Kubernetes and 68s on VS Code. Fixes #5667.Summary
Each source's breadth first search now runs one level at a time with numpy over a CSR copy of the adjacency. Every floating point sum keeps networkx's order, so the scores match
nx.betweenness_centralityto the last bit. Graphs with narrow levels fall back to the existing scalar loop._betweenness_centralitywith k=100Each number is the median of 3 runs on a 16 vCPU Linux machine with CPython 3.12 and numpy 1.26. Cold builds match v8 byte for byte.
Limitations: exact scores rely on
np.bincountadding in input order. numpy does this but does not document it, so the tests pin it. The speedup is smaller before numpy 1.25, and a 50 node graph takes 1.8ms instead of 1.1ms.Test plan