Skip to content

Make Leiden faster than Louvain - #316

Merged
forhappy merged 3 commits into
mainfrom
codex/optimize-leiden-hot-paths
Sep 13, 2026
Merged

Make Leiden faster than Louvain#316
forhappy merged 3 commits into
mainfrom
codex/optimize-leiden-hot-paths

Conversation

@forhappy

Copy link
Copy Markdown
Contributor

Summary

  • follow up merged PR Optimize Leiden community detection performance #315 with the remaining Leiden hot-path optimizations
  • reuse dense neighbor scratch space, cache per-level graph statistics, and roll back rejected passes with a move journal
  • borrow the first graph level, skip redundant full-graph subgraphs, and defer member materialization until convergence
  • reduce typed-topology and evidence allocation while preserving canonical ordering and exact floating-point accumulation
  • preserve byte-identical partition and quality output with reference-equivalence regression coverage

Performance

Fresh release-process measurements used 5 warmups and 51 alternating observations per algorithm on FastAPI pinned at 0c2b6aafd7a2e3a5bf1055ea0ed0a41da15ba5f4.

Graph profile Louvain median Leiden median Leiden / Louvain
max inference, 4,152 nodes / 10,038 links 205.449 ms 202.579 ms 0.986x
low inference, 2,335 nodes / 3,370 links 78.761 ms 74.355 ms 0.944x

Leiden is 1.4% faster on the max-inference graph and 5.6% faster on the low-inference graph. In the release in-process compact qualification, fixed Leiden is 0.611x Louvain latency (39% faster). Median peak RSS on the max graph is 136.13 MiB versus 134.19 MiB for Louvain, a 1.44% overhead.

The fixed-Leiden max-graph output SHA-256 remains exactly 4f26ed16c66b5f939e2436255dfff884defa431392b26a3e322c331f957a4e75; community count and quality metrics are unchanged.

Verification

  • cargo fmt --all -- --check
  • cargo test -p compass-graph --locked
  • cargo clippy -p compass-graph --all-targets --all-features --locked -- -D warnings
  • cargo clippy --workspace --lib --bins --locked -- -D warnings
  • cargo test --workspace --lib --bins --locked
  • ./scripts/qualify_code_graph_v1.sh --fixtures-only
  • ./scripts/qualify_code_graph_v1.sh --community-quality --report /Volumes/Workspace/crabbuild-target/compass-c112/community-quality-optimized.json
  • sh scripts/check_product_boundary.sh
  • git diff --check

The generated community-quality report is byte-identical to the checked-in qualification artifact.

@forhappy
forhappy merged commit 689809d into main Sep 13, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant