Skip to content

Higher resolution for monotonic-clock.wait-* #14364

Description

@Destructor17

Feature

monotonic-clock.wait-until and monotonic-clock.wait-for in WASIp3 (and probably corresponding pollables in WASIp2) are implemented using tokio::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_hrtime is just the first thing that pops up while googling. Have not researched this topic in-depth, but there should be more implementations, although tokio_hrtime works 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    wasi:implIssues pertaining to WASI implementation in Wasmtime

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions