mirror of
https://github.com/denoland/deno.git
synced 2025-09-30 22:21:15 +00:00
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. 
This commit is contained in:
parent
d4f1bd3dac
commit
73fbd61bd0
6 changed files with 73 additions and 44 deletions
|
@ -2,7 +2,6 @@
|
|||
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::time;
|
||||
|
||||
use deno_core::error::generic_error;
|
||||
use deno_core::error::type_error;
|
||||
|
@ -13,6 +12,7 @@ use deno_core::ModuleSpecifier;
|
|||
use deno_core::OpState;
|
||||
use deno_runtime::deno_permissions::ChildPermissionsArg;
|
||||
use deno_runtime::deno_permissions::PermissionsContainer;
|
||||
use deno_runtime::deno_web::StartTime;
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
use uuid::Uuid;
|
||||
|
||||
|
@ -148,7 +148,7 @@ fn op_dispatch_bench_event(state: &mut OpState, #[serde] event: BenchEvent) {
|
|||
#[op2(fast)]
|
||||
#[number]
|
||||
fn op_bench_now(state: &mut OpState) -> Result<u64, std::num::TryFromIntError> {
|
||||
let ns = state.borrow::<time::Instant>().elapsed().as_nanos();
|
||||
let ns = state.borrow::<StartTime>().elapsed().as_nanos();
|
||||
let ns_u64 = u64::try_from(ns)?;
|
||||
Ok(ns_u64)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue