Stop rescanning the job backlog when picking the next tier2 job - #923
Merged
Conversation
The scan cursor stopped at the squasher because every higher stage holds pending units from there to the job frontier, all waiting on the lower stage's previous segment, so each call walked that backlog again. Per-stage cursors now give the lowest pending segment and the completed prefix, and a stage can only run at or below the prefix of the stages under it, so a call visits one segment per stage plus the shadow window. 8000 segments with a slow squasher: 1.18 s to 2.7 ms, growth now linear.
billettc
approved these changes
Sep 3, 2026
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.
Picking the next tier2 job walked every segment between the squasher and the job frontier on every call, re-checking dependencies that could not have changed: every stage above 0 holds Pending units across that whole backlog, each waiting on the stage below to squash the previous segment. The scheduler now keeps, per stage, the lowest segment that may be Pending and the completed prefix, and a stage can only run at or below the prefix of the stages under it, so a call visits one segment per stage plus the shadow window. Every transition back to Pending rewinds the cursors, so a map output found missing is still re-scheduled. Job order is unchanged.
Measured, 3 stages, 4 workers, squasher 3x slower than the jobs, whole run:
Before grew 3.9x per doubling of the range, after 2x. Per call at 8000 segments: 27 µs to 62 ns.
In perspective, with 1000-block segments: at 400M blocks (Solana, Arbitrum) a call cost about 3 ms with 3 stages, about 6 ms with 5, and the scheduler loop makes 5 to 9 calls per job. That is a few percent of one core on a normal full-history run, and only became the bottleneck in noop or store-only mode with fast jobs and many workers, where the loop saturated while tier2 waited. In production mode the walker already bounds the backlog to a few hundred segments, so nothing changes there.