This repository was archived by the owner on Sep 8, 2025. It is now read-only.
Commit ef11ee9
committed
refactor/rewrite
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>concurrent.rs event loop1 parent 66bd2cb commit ef11ee9
18 files changed
Lines changed: 1382 additions & 1736 deletions
File tree
- crates
- test-programs/src/bin
- wasmtime/src/runtime
- component
- concurrent
- func
- externals
- func
- store
- tests/all/component_model
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
105 | 110 | | |
106 | 111 | | |
107 | 112 | | |
| |||
292 | 297 | | |
293 | 298 | | |
294 | 299 | | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
303 | 308 | | |
304 | | - | |
305 | | - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
306 | 333 | | |
307 | 334 | | |
308 | 335 | | |
| |||
327 | 354 | | |
328 | 355 | | |
329 | 356 | | |
330 | | - | |
| 357 | + | |
331 | 358 | | |
332 | 359 | | |
333 | 360 | | |
| |||
337 | 364 | | |
338 | 365 | | |
339 | 366 | | |
340 | | - | |
| 367 | + | |
341 | 368 | | |
342 | 369 | | |
343 | 370 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | 105 | | |
110 | | - | |
111 | 106 | | |
112 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
113 | 116 | | |
114 | 117 | | |
115 | 118 | | |
| |||
Lines changed: 5 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
| |||
0 commit comments