perf(fringe): stop scanning the whole fringe on every relaxed edge - #810
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.removegoes 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
fringetests, 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.