Skip to content

perf(ui): replace O(n*e) edge mapping with binary search#170

Open
Selene29 wants to merge 1 commit intoDeusData:mainfrom
Selene29:perf/layout-edge-binary-search
Open

perf(ui): replace O(n*e) edge mapping with binary search#170
Selene29 wants to merge 1 commit intoDeusData:mainfrom
Selene29:perf/layout-edge-binary-search

Conversation

@Selene29
Copy link
Copy Markdown

Fixes #169

Summary

  • Replace two-pass fetch-then-map edge filtering with single-pass filter-during-fetch using sorted node-ID array and binary search
  • O(n log n + e log n) instead of O(n × e) — eliminates multi-second hangs on large projects
  • Free rejected edges immediately, reducing peak memory

Test plan

  • scripts/test.sh SANITIZE= passes (2507 passed, 61 skipped)
  • Layout endpoint renders large repos without timeout

The layout endpoint's edge-to-node mapping used a linear scan over all
nodes for every edge, producing O(n*e) iterations. For large projects
(100K+ nodes, 400K+ edges) this caused multi-second hangs or timeouts.

Replace the two-pass fetch-then-map approach with a single-pass
filter-during-fetch using a sorted node-ID array and binary search:

- Build a sorted node_id_entry_t map after querying nodes
- For each fetched edge, binary search both endpoints — O(log n) each
- Only keep edges where both endpoints are in the selected node set
- Compute degree inline, eliminating the separate mapping loop
- Free rejected edges immediately to minimize peak memory
@DeusData DeusData added the stability/performance Server crashes, OOM, hangs, high CPU/memory label Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stability/performance Server crashes, OOM, hangs, high CPU/memory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(ui): layout endpoint O(n*e) edge mapping causes timeouts on large projects

2 participants