Skip to content

perf(fringe): stop scanning the whole fringe on every relaxed edge - #810

Merged
samueltardieu merged 1 commit into
evenfurther:mainfrom
tachsin:perf/fringe-lazy-deletion
Sep 9, 2026
Merged

perf(fringe): stop scanning the whole fringe on every relaxed edge#810
samueltardieu merged 1 commit into
evenfurther:mainfrom
tachsin:perf/fringe-lazy-deletion

Conversation

@tachsin

@tachsin tachsin commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Closes #806.

Leaves stale queue entries in place instead of scanning for them. Each entry carries the value stamps[node] held when it was queued; relaxing a node bumps its stamp, so older entries are recognised and skipped when they surface. The node is still pushed to the front, so it is still reached first, and the work per relaxed edge drops to a push.

remove goes away with it.

Checking

The search itself is unchanged: the same nodes are expanded under the same limits, and the same path comes out. Verified against Bellman-Ford over 300 random graphs, and the existing fringe tests, including the GPS and r299 ones, are untouched.

About 42% off a 200x200 weighted grid, measured against this branch's parent. The gap widens with the size of the fringe.

All timings measured on Windows 11, Intel Core Ultra 7 265K, 64 GB RAM.

Reaching a node through a cheaper path has to move it back to the front of the
current list. `remove` finds it by walking `later` and then `now` from one end,
comparing indices, so every relaxed edge costs a pass over the fringe. The
fringe is large for exactly the searches that matter, which makes the inner
loop quadratic in its size.

Leave the stale entries where they are instead. Each queue entry carries the
value `stamps[node]` held when it was queued, and relaxing a node bumps its
stamp, so the older entries are recognised and skipped when they come up. The
node is pushed to the front as before, so it is still reached first, and the
work per edge drops to a push.

Nothing else about the search changes: the same nodes are expanded under the
same limits, and paths are checked against Bellman-Ford over 300 random graphs.

About 42% off a 200x200 weighted grid. The gap widens with the size of the
fringe, so larger searches gain more.
@samueltardieu
samueltardieu added this pull request to the merge queue Sep 9, 2026
Merged via the queue into evenfurther:main with commit e8a1527 Sep 9, 2026
11 of 12 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.

fringe scans the whole fringe on every relaxed edge, making it quadratic in its size

2 participants