Skip to content

graphify update is O(V×E) on large repos due to betweenness_centrality in suggest_questions #341

Closed

Description

@loktarjugg

Problem

graphify update <path> becomes extremely slow on large monorepos (50k+ files, ~450k nodes, ~690k edges). On a 96-core Xeon server, the command ran for 114 minutes without completing and had to be killed.

Root Cause

_rebuild_code() in watch.py calls suggest_questions() in analyze.py, which runs:

betweenness = nx.betweenness_centrality(G)

nx.betweenness_centrality has O(V × E) time complexity. For our graph (450k nodes × 690k edges = ~310 billion operations), this is infeasible in single-threaded Python.

Timeline breakdown on 96-core Xeon 8163 @ 2.5GHz:

Phase Time Status
AST extraction (55,903 files, cache hit) ~6 min OK
build_from_json (450k nodes) ~5 min OK
cluster (Leiden via graspologic) ~15 min OK
score_all unknown —
surprising_connections unknown —
suggest_questions → betweenness_centrality 90+ min, never finished Bottleneck

For reference, the same repo builds in ~10 min on Apple M3 Pro (4.8x faster single-core), suggesting betweenness_centrality dominates even locally.

Environment

  • graphifyy 0.4.11
  • Python 3.11
  • NetworkX 3.6.1
  • graspologic installed (Leiden works fine)
  • Repo: 55,903 code files across 83 git submodules

Suggested Fix

For large graphs, suggest_questions should either:

  1. Skip betweenness_centrality when node count exceeds a threshold (e.g. 10k nodes)
  2. Use approximate betweenness (nx.betweenness_centrality with k parameter for sampling)
  3. Make the analyze/report phase optional in _rebuild_code() — the graph.json is the valuable output, not the report

Option 3 would be most impactful — users running graphify update on large repos primarily want the graph.json for MCP tool queries, not the GRAPH_REPORT.md.

Workaround

Currently we have no workaround other than building locally on a faster machine. A --skip-report flag on graphify update would unblock server-side builds immediately.

Activity

  1. safishamsi commented on Apr 14, 2026

    @safishamsi
    Member

    Implemented in v0.4.14.

    pip install --upgrade graphifyy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions