diff options
author | snek <snek@deno.com> | 2024-11-08 23:20:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-08 23:20:24 +0100 |
commit | 73fbd61bd016eebbf2776dc94c15a26bf39668d6 (patch) | |
tree | c7e5f4ee47f94f2279e745b1825959f82a66a22d /ext/web/lib.rs | |
parent | d4f1bd3dacf54c4625eef7828341b39286ead8cb (diff) |
fix: performance.timeOrigin (#26787)
`performance.timeOrigin` was being set from when JS started executing,
but `op_now` measures from an `std::time::Instant` stored in `OpState`,
which is created at a completely different time. This caused
`performance.timeOrigin` to be very incorrect. This PR corrects the
origin and also cleans up some of the timer code.
Compared to `Date.now()`, `performance`'s time origin is now
consistently within 5us (0.005ms) of system time.

Diffstat (limited to 'ext/web/lib.rs')
-rw-r--r-- | ext/web/lib.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/ext/web/lib.rs b/ext/web/lib.rs index 4935af5bd..af0fc2c27 100644 --- a/ext/web/lib.rs +++ b/ext/web/lib.rs @@ -52,7 +52,8 @@ pub use crate::message_port::Transferable; use crate::timers::op_defer; use crate::timers::op_now; -use crate::timers::StartTime; +use crate::timers::op_time_origin; +pub use crate::timers::StartTime; pub use crate::timers::TimersPermission; deno_core::extension!(deno_web, @@ -84,6 +85,7 @@ deno_core::extension!(deno_web, compression::op_compression_write, compression::op_compression_finish, op_now<P>, + op_time_origin<P>, op_defer, stream_resource::op_readable_stream_resource_allocate, stream_resource::op_readable_stream_resource_allocate_sized, @@ -123,7 +125,7 @@ deno_core::extension!(deno_web, if let Some(location) = options.maybe_location { state.put(Location(location)); } - state.put(StartTime::now()); + state.put(StartTime::default()); } ); |