Destructor17 opened issue #14364:
Feature
monotonic-clock.wait-untilandmonotonic-clock.wait-forin WASIp3 (and probably corresponding pollables in WASIp2) are implemented usingtokio::time::sleep, which is kinda inaccurate in terms of waiting. It seem to have 1ms resolution on UNIX and up to ~16ms on Windows. It would be nice to have a higher-resolution sleep primitive.Benefit
It's not observable on workloads Wasmtime is usually used for, but such inaccuracy has high impact on GUI apps if sleep between frames is implemented in guest code. In my case 1ms resolution makes FPS drop from 60 to 58 on UNIX and to 30 on Windows.
Implementation
This can be solved by simply using tokio_hrtime, a drop-in replacement for
tokio::time.Alternatives
Well,
tokio_hrtimeis just the first thing that pops up while googling. Have not researched this topic in-depth, but there should be more implementations, althoughtokio_hrtimeworks fine for me.As for Windows, this problem can also be (partially) solved by calling timeBeginPeriod function to increase resolution to 1ms, but they say it makes Windows waste CPU cycles.
Destructor17 edited issue #14364:
Feature
monotonic-clock.wait-untilandmonotonic-clock.wait-forin WASIp3 (and probably corresponding pollables in WASIp2) are implemented usingtokio::time::sleep, which is kinda inaccurate in terms of waiting. It seem to have 1ms resolution on UNIX and up to ~16ms on Windows. It would be nice to have a higher-resolution sleep primitive.Benefit
It's not observable on workloads Wasmtime is usually used for, but such inaccuracy has high impact on GUI apps if sleep between frames is implemented in guest code. In my case it makes FPS drop from 60 to 58 on UNIX and to 30 on Windows.
Implementation
This can be solved by simply using tokio_hrtime, a drop-in replacement for
tokio::time.Alternatives
Well,
tokio_hrtimeis just the first thing that pops up while googling. Have not researched this topic in-depth, but there should be more implementations, althoughtokio_hrtimeworks fine for me.As for Windows, this problem can also be (partially) solved by calling timeBeginPeriod function to increase resolution to 1ms, but they say it makes Windows waste CPU cycles.
Destructor17 edited issue #14364:
Feature
monotonic-clock.wait-untilandmonotonic-clock.wait-forin WASIp3 (and probably corresponding pollables in WASIp2) are implemented usingtokio::time::sleep, which is kinda inaccurate in terms of waiting. It seem to have 1ms resolution on UNIX and up to ~16ms on Windows. It would be nice to have a higher-resolution sleep primitive.Benefit
It's not observable on workloads Wasmtime is usually used for, but such inaccuracy has high impact on GUI apps if sleep between frames is implemented in guest code. In my case it makes FPS drop from 60 to 58 on UNIX and to 30 on Windows.
Implementation
This can be solved by simply using tokio_hrtime, a drop-in replacement for
tokio::time.Alternatives
Well,
tokio_hrtimeis just the first thing that pops up while googling. Have not researched this topic in-depth, but there should be more implementations, althoughtokio_hrtimeworks fine for me.As for Windows, this problem can also be (partially) solved by calling timeBeginPeriod function to increase resolution to 1ms, but they say it makes Windows waste CPU cycles.
Update:
Another alternative is just allowing embedder to override asynchronous wait for WASIp3 by watever-they-want. Overriding it for WASIp2 also seem to be possible.
alexcrichton added the wasi:impl label to Issue #14364.
alexcrichton commented on issue #14364:
Thanks for the report! FWIW with
Linker::allow_shadowingit should be possible to swap in your own implementation ofwasi:clocksfor wasip2/wasip3. If you're using thewasmtimeCLI, however, that'll not work there.
fitzgen added the enhancement label to Issue #14364.
Last updated: Oct 11 2026 at 04:10 UTC