perf: Iterate dataflow blocks in traversal order [pathological loop/await CFGs -52%/-82%; primary ~neutral] - #76
Draft
xmakro wants to merge 1 commit into
Draft
Conversation
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.
The dataflow fixpoint seeds its work queue in reverse postorder, but the queue itself is a plain FIFO, so on loop-heavy control flow graphs it degenerates into breadth-first iteration and revisits blocks many more times than it needs to. This replaces it with a queue that yields dirty blocks in traversal-order sweeps, tracking dirtiness in a bitset keyed by traversal position and walking it with a cursor instead of pushing and popping a deque. Blocks with no traversal position, which only backward analyses reach via predecessors of unreachable blocks, are drained separately after the ordered sweep.
A strict "always take the lowest position" rule was tried first and rejected. It is considerably worse than the current FIFO on a block joined from many back edges, such as a coroutine resume dispatch, because it returns to the join once per back edge rather than once per sweep.
The fixpoint result is unchanged: a monotone dataflow fixpoint does not depend on iteration order, and this was checked against the old queue over randomly generated control flow graphs in both directions. tests/ui and tests/incremental both pass.