This repository was archived by the owner on Sep 8, 2025. It is now read-only.
refactor/rewrite concurrent.rs event loop#143
Merged
Conversation
d45126a to
a89bf44
Compare
The event loop and scheduler in `concurrent.rs` have undergone a lot of changes
over time, reflecting significant changes in the component model spec. Some
features, such as yielding, backpressure, and waitable sets, were retrofitted
onto the existing code in a somewhat haphazard way, making the code more
convoluted than it needed to be. In addition, it made control flow hard to
understand and debug, with multiply-nested fibers and no clear division of
responsibility among tasks and the fibers they ran on.
This commit rewrites most of that code to make it more cohesive:
- No nested fibers: we always suspend the current fiber before resuming the next one
- One single function (`poll_until`) runs the event loop (rather than several functions with slightly different semantics, as before)
- The code paths for `{Typed}Func::call_{async,concurrent}` have been unified, reducing redundancy and unsafe code
- We now manage reentrance, yielding, and backpressure by explicitly deferring work as appropriate
- Work is deferred to either:
- a high priority queue (work to be done ASAP)
- a low priority queue (work to be done only once the high priority queue has been drained)
- a per-instance `pending` bucket (work that can't be done until a current activation for that instance returns and/or backpressure is unset)
- The new code is more `waitable-set`-native, removing obsolete ties between parent and child tasks which no longer apply
- Fixed previous unsoundness due to recursively modifying `ConcurrentState::futures` while polling it
- More types implement `Debug`, making logs easier to follow
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
a89bf44 to
ef11ee9
Compare
`StoreFiber`s are now stored in a few other places besides `ConcurrentState::table`, so we need to clear those out as well. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
This was referenced Apr 30, 2025
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 event loop and scheduler in
concurrent.rshave undergone a lot of changes over time, reflecting significant changes in the component model spec. Some features, such as yielding, backpressure, and waitable sets, were retrofitted onto the existing code in a somewhat haphazard way, making the code more convoluted than it needed to be. In addition, it made control flow hard to understand and debug, with multiply-nested fibers and no clear division of responsibility among tasks and the fibers they ran on.This commit rewrites most of that code to make it more cohesive:
poll_until) runs the event loop (rather than several functions with slightly different semantics, as before){Typed}Func::call_{async,concurrent}have been unified, reducing redundancy and unsafe codependingbucket (work that can't be done until a current activation for that instance returns and/or backpressure is unset)waitable-set-native, removing obsolete ties between parent and child tasks which no longer applyConcurrentState::futureswhile polling itDebug, making logs easier to follow