Skip to content

perf(cluster): count community overlaps from shared nodes - #5382

Closed
Max17190 wants to merge 1 commit into
Graphify-Labs:v8from
Max17190:perf/sparse-community-overlaps
Closed

Max17190 wants to merge 1 commit into
Graphify-Labs:v8from
Max17190:perf/sparse-community-overlaps

Conversation

@Max17190

@Max17190 Max17190 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Why

graphify update and cluster-only carry community IDs forward by member overlap so saved labels follow their communities. The remapper currently intersects every old community with every new one, even when the two share no members.

Summary

  • Count overlaps from each distinct new member's previous community ID. Only pairs with shared members enter the ranking.
  • Preserve the greedy assignment. Equal overlaps prefer the lower previous community ID, then the lower new community ID.
  • Count repeated members once and preserve the returned member list. The tests check these behaviors separately.

Related to #2298, which documents how saved labels depend on matching communities across builds.

Starting from the same cached 27k-node Graphify graph, five interleaved cluster-only runs per variant on arm64 macOS and Python 3.13 gave these medians and ranges.

Measurement Before After
Remapping 211.49 ms (210.63 to 217.21 ms) 4.42 ms (4.26 to 4.50 ms)
Whole command 3.495 s (3.481 to 3.610 s) 3.284 s (3.267 to 3.315 s)

In a separate paired one-file update on Guava's 84k-node graph, the remap stage took 698 ms before and 12 ms after.

Type of change

  • Refactor

Verification & Invariants

For the same pair of partitions, the revised remapper returns the same community IDs and ordered member lists as the original. Equal overlap counts resolve in the same order. This keeps saved labels attached to the same communities. The remapper counts each distinct member once, including when an input member list contains duplicates.

Test Plan

  • python -m pytest -q tests/test_cluster.py tests/test_watch.py passed 244 tests with one skip after the test cases were clarified.
  • python -m graphify update . rebuilt the graph.
  • python -P -m pytest -q tests yielded 11,734 passes, 135 skips, and 1 expected failure. Eight DNS and Unix-socket failures reproduced on upstream and passed when re-run outside the sandbox. Six Terraform worker cases passed on the isolated rerun of tests/test_terraform_modules.py.
  • ruff check . and python -P -m tools.skillgen --check
  • Compared Pyright diagnostics with upstream using the same interpreter. No new diagnostics.
  • Compared graphify update . and graphify cluster-only . against upstream on Graphify and Guava. The graph, HTML, report, and emitted community sidecars matched byte for byte.
  • Compared exact remapper output on 2,000 randomized partitions per interpreter on Python 3.11, 3.12, 3.13, and 3.14.
  • Independently compared ordered output against the original remapper on 204,800 exhaustive small partitions and 25,000 seeded random partitions. The comparisons cover partial overlap, ties, and duplicate members.

Graphify-specific checklist

  • Read the contribution guide and checked deterministic structural output.
  • Verified that persisted community IDs and labels match the baseline.
  • Checked generated skill artifacts.
  • Disclosed authorship in the commit metadata.

@Max17190
Max17190 requested a review from safishamsi as a code owner November 21, 2026 19:42
@github-actions

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 21, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify review View in Graphify

Looks safe to merge · Merge confidence 5/5

No issues reported · High impact

The remapping function now counts shared nodes by previous community using Counter, rather than comparing every old and new community pair.

Code graph · 846 functions depend on this change
  • 23 of 607 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed 713a856 · 3 earlier findings not re-checked · Full report in the Graphify check

Community remapping keeps saved labels aligned after rebuilds. Count
intersections only for pairs that share a node, and pin the existing
tie-break and duplicate-member behavior in separate tests.

Refs Graphify-Labs#2298

Co-Authored-By: OpenAI Codex <[email protected]>
@Max17190
Max17190 force-pushed the perf/sparse-community-overlaps branch from 8bd6e9e to 713a856 Compare November 21, 2026 20:56
safishamsi added a commit that referenced this pull request Nov 23, 2026
…batch

Fold the C (#5410) and C# (#5043) AST-output changes into one combined
_AST_CACHE_SCHEMA bump 52 -> 53 (52 is held by the unreleased 0.9.116 ObjC
train), so cached C and C# extractions re-run. The go, cluster and extract
fixes change no cached AST output. 0.9.118 changelog and version bump.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.118 via an authorship-preserving cherry-pick, so your commit keeps its credit. The overlap count is now O(total members) from shared nodes instead of O(communities²) pairwise intersections, with byte-identical results. Thanks @Max17190!

@safishamsi safishamsi closed this Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants