adamrk opened PR #14350 from adamrk:abk/deferred-host-task to bytecodealliance:main:
Defer creation of a
HostTaskand insertion of it in theStoreuntil it is required. This is an optimization on wasm->host calls where theHostTaskmay not actually be needed. TheHostTaskis materialized if the host future actually suspends (doesn't returnReadyon the first poll), or if it tries to lower a borrowed resource (which requires inserting itsCallContextinto theStoreto get a persistent identifier for it).The work is separated into 3 commits:
- Add benchmarks for nop wasm->host calls that pass a borrow and where the host suspends before returning.
- Make the
u32identifier forCallContexts an proper enum- The actual change of deferring
HostTaskcreation.These are the changes I see in the wasm->host benchmarks:
Baseline benchmarks:component-async/wasm-to-host time: [354.02 ns 366.83 ns 380.05 ns] component-async/wasm-to-host-borrow time: [462.76 ns 479.96 ns 497.66 ns] component-async/wasm-to-host-pending-once time: [2.5383 µs 2.6139 µs 2.6873 µs]With changes:
component-async/wasm-to-host time: [283.83 ns 296.05 ns 308.65 ns] change: [−21.162% −17.822% −14.374%] (p = 0.00 < 0.05) Performance has improved. component-async/wasm-to-host-borrow time: [377.80 ns 392.33 ns 406.01 ns] change: [−31.982% −29.587% −26.924%] (p = 0.00 < 0.05) Performance has improved. component-async/wasm-to-host-pending-once time: [2.4307 µs 2.5107 µs 2.5932 µs] change: [−3.0505% +0.1437% +3.5901%] (p = 0.94 > 0.05) No change in performance detected.
github-actions[bot] added the label wasmtime:api on PR #14350.
adamrk updated PR #14350.
adamrk updated PR #14350.
adamrk updated PR #14350.
adamrk has marked PR #14350 as ready for review.
adamrk requested dicej for a review on PR #14350.
adamrk requested wasmtime-core-reviewers for a review on PR #14350.
adamrk requested alexcrichton for a review on PR #14350.
adamrk requested wasmtime-default-reviewers for a review on PR #14350.
:thumbs_up: alexcrichton submitted PR review:
Some great wins, thanks!
:speech_balloon: alexcrichton created PR review comment:
Could this be moved into
host_task_create? To the extent thatset_threadis a somewhat-hot function and I think that's the only caller which would otherwise trigger this, it might help keep this function a bit leaner to move it over there. That might mess up and/or require moving around some debug assertions though
:speech_balloon: alexcrichton created PR review comment:
Could you add a debug-assert on this branch that
materialized_taskisNone?
:speech_balloon: alexcrichton created PR review comment:
And, similarly, for handling
deferred_host_call_contextgetting cleared above, could that move into thefirst_pollfunction or similar?
Last updated: Sep 20 2026 at 18:08 UTC