Skip to content

clock_time_get defaults to Date.now() rather than performance.now() #27063

@curiousdannii

Description

@curiousdannii

The WASI function clock_time_get is meant to return nanosecond precision, but Emscripten's implementation uses Date.now() in realtime mode rather than performance.now(). The latter can at best only do microsecond precision, but that's much better than the former's millisecond precision. (Browsers will typically restrict it to 100 microsec precision, but that's still 10 times better than Date.now(). Node should get the full microsec detail.)

I'm sure there are lots of tricky edge cases here which I don't know about, but this seems like it should be broadly possible?

if (clk_id === {{{ cDefs.__WASI_CLOCKID_REALTIME }}}) {
now = _emscripten_date_now();
} else if (nowIsMonotonic) {
now = _emscripten_get_now();

Something like this?

if (clk_id === {{{ cDefs.__WASI_CLOCKID_REALTIME }}}) {
      now = performance.timeOrigin + _emscripten_get_now();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions