posborne added the bug label to Issue #10667.
posborne opened issue #10667:
Credit to @aturon for the discovery...
Today, the
async_yield_implbehavior triggered an epoch deadline is hit or we run out of fuel does not match that oftokio::task::yield_now. They are _mostly_ the same except that with the current implementation that wasm task effectively gets immediately rescheduled (it is not deferred and ends up at the front rather than the back of the pending queue). This would not necessarily be the case with all task schedulers but is the case with tokio today in its default configuration with the lifo-slot enabled (seetokio::runtime::Builder::disable_lifo_slot).When targeting tokio, it would be preferred to have the async yield behavior map directly to whatever
tokio::task::yield_nowdoes. There seems to be a couple ways to approach this:
- Feature flagging to enable the direct call.
- Allow embedder to configure the async yield behavior to allow for
yield_nowto be called.Secondarily, even if the lifo-slot was disabled, the
yield_nowbehavior in tokio has the added benefit of not allowing the yielding task to be immediately stolen as it is first moved to the deferred queue. If the current worker does not end up picking up other blocking work then we'll end up resuming on the same thread and avoid potential thrashing.
fitzgen commented on issue #10667:
We jsut talked about this in the Wasmtime biweekly.
Gist was that we already support calling a callback at epoch interruption points and it makes sense to add an async variation of this callback API. This would allow embedders to call
tokio::task::yield_now()from that async callback, while keeping the core of wasmtime free of any assumptions of which particular async executor is being used.
posborne closed issue #10667:
Credit to @aturon for the discovery...
Today, the
async_yield_implbehavior triggered an epoch deadline is hit or we run out of fuel does not match that oftokio::task::yield_now. They are _mostly_ the same except that with the current implementation that wasm task effectively gets immediately rescheduled (it is not deferred and ends up at the front rather than the back of the pending queue). This would not necessarily be the case with all task schedulers but is the case with tokio today in its default configuration with the lifo-slot enabled (seetokio::runtime::Builder::disable_lifo_slot).When targeting tokio, it would be preferred to have the async yield behavior map directly to whatever
tokio::task::yield_nowdoes. There seems to be a couple ways to approach this:
- Feature flagging to enable the direct call.
- Allow embedder to configure the async yield behavior to allow for
yield_nowto be called.Secondarily, even if the lifo-slot was disabled, the
yield_nowbehavior in tokio has the added benefit of not allowing the yielding task to be immediately stolen as it is first moved to the deferred queue. If the current worker does not end up picking up other blocking work then we'll end up resuming on the same thread and avoid potential thrashing.
Last updated: Dec 06 2025 at 06:05 UTC