Skip to content

Split grid neighbor search into broad and narrow phases - #19

Merged
nhz2 merged 1 commit into
mainfrom
grid-candidate-buffer
Oct 25, 2026
Merged

nhz2 merged 1 commit into
mainfrom
grid-candidate-buffer

Conversation

@nhz2

@nhz2 nhz2 commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

The broad phase now only runs the box overlap test on grid entries and buffers candidate i => j pairs, already in NeighborListEdge order, in a GridCandidates buffer. It no longer loads positions, radii, or params. The overlap test is branchless: every checked pair is written at n + 1 and n only advances on a hit. _grid_make_room! runs before each run of entries, flushing the buffer through the narrow phase or growing it, so the inner loops never check for room.

The narrow phase filters the buffer by distance in place, then applies filter_pair, the exclusions, and mix_params, and pushes the edges.

Ring benchmark, single thread: 1.21 ms -> 0.95 ms.

The broad phase now only runs the box overlap test on grid entries and
buffers candidate `i => j` pairs, already in `NeighborListEdge` order, in
a `GridCandidates` buffer. It no longer loads positions, radii, or params.
The overlap test is branchless: every checked pair is written at `n + 1`
and `n` only advances on a hit. `_grid_make_room!` runs before each run
of entries, flushing the buffer through the narrow phase or growing it,
so the inner loops never check for room.

The narrow phase filters the buffer by distance in place, then applies
`filter_pair`, the exclusions, and `mix_params`, and pushes the edges.

Replace the pair type tuple with a `GridPairType` struct and delete
`_grid_push_edge!`.

Ring benchmark, single thread: 1.21 ms -> 0.95 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nhz2
nhz2 merged commit 2de85b5 into main Oct 25, 2026
2 checks passed
@nhz2
nhz2 deleted the grid-candidate-buffer branch October 25, 2026 07:02
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