Skip to content

perf(layout): Prune force-overlap resolution with a uniform spatial grid#87

Merged
mhiro2 merged 1 commit into
mainfrom
perf/layout-overlap-resolver-spatial-grid
Apr 26, 2026
Merged

perf(layout): Prune force-overlap resolution with a uniform spatial grid#87
mhiro2 merged 1 commit into
mainfrom
perf/layout-overlap-resolver-spatial-grid

Conversation

@mhiro2

@mhiro2 mhiro2 commented Apr 26, 2026

Copy link
Copy Markdown
Owner

Summary

  • Cut force-directed overlap resolution from O(80 × N²) all-pairs to a per-pass uniform spatial grid so cost scales with locality on large schemas
  • Keep per-pair push semantics and output determinism by sorting collected candidate pairs before traversal
  • Add a 6x6 stress test that fails if the grid binning ever misses a real overlap pair

Changes

  • 5691c08 : perf(layout): prune resolve_force_overlaps with a uniform spatial grid
    • Bin nodes per pass by their top-left cell with cell_size = max(W, H) + padding, the threshold above which two padded AABBs cannot overlap
    • Walk forward neighbours (1,0), (0,1), (1,1), (-1,1) so each cross-cell pair is reported exactly once and sort_unstable makes traversal independent of HashMap iteration order
    • Add test_resolve_force_overlaps_grid_handles_many_nodes covering a dense overlapping grid to lock in the spatial-pruning correctness

Replace the all-pairs O(N^2) scan in resolve_force_overlaps with a
uniform spatial grid that bins nodes by their top-left corner. Cell
size is chosen so any two padded AABBs that actually overlap fall
into the same or an adjacent cell, letting the per-pass cost scale
with locality instead of N^2. Candidate pairs are sorted before
traversal so HashMap iteration order does not affect output, and a
6x6 stress test guards against missed pairs.
@mhiro2 mhiro2 self-assigned this Apr 26, 2026
@mhiro2 mhiro2 added the enhancement New feature or request label Apr 26, 2026
@github-actions

Copy link
Copy Markdown

Code Metrics Report

main (2a84f2a) #87 (6720382) +/-
Coverage 94.6% 94.7% +0.0%
Test Execution Time 1m26s 1m22s -4s
Details
  |                     | main (2a84f2a) | #87 (6720382) |  +/-  |
  |---------------------|----------------|---------------|-------|
+ | Coverage            |          94.6% |         94.7% | +0.0% |
  |   Files             |             77 |            77 |     0 |
  |   Lines             |          34196 |         34255 |   +59 |
+ |   Covered           |          32383 |         32442 |   +59 |
+ | Test Execution Time |          1m26s |         1m22s |   -4s |

Code coverage of files in pull request scope (95.7% → 95.7%)

Files Coverage +/- Status
crates/relune-layout/src/layout.rs 95.7% +0.0% modified

Reported by octocov

@mhiro2
mhiro2 merged commit 0c5b241 into main Apr 26, 2026
4 checks passed
@mhiro2
mhiro2 deleted the perf/layout-overlap-resolver-spatial-grid branch April 26, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant