mirror of
https://github.com/denoland/deno.git
synced 2025-08-31 15:57:53 +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
|
@ -1,12 +1,9 @@
|
|||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { core, primordials } from "ext:core/mod.js";
|
||||
import { op_defer, op_now } from "ext:core/ops";
|
||||
import { op_defer } from "ext:core/ops";
|
||||
const {
|
||||
Uint8Array,
|
||||
Uint32Array,
|
||||
PromisePrototypeThen,
|
||||
TypedArrayPrototypeGetBuffer,
|
||||
TypeError,
|
||||
indirectEval,
|
||||
ReflectApply,
|
||||
|
@ -18,13 +15,6 @@ const {
|
|||
|
||||
import * as webidl from "ext:deno_webidl/00_webidl.js";
|
||||
|
||||
const hrU8 = new Uint8Array(8);
|
||||
const hr = new Uint32Array(TypedArrayPrototypeGetBuffer(hrU8));
|
||||
function opNow() {
|
||||
op_now(hrU8);
|
||||
return (hr[0] * 1000 + hr[1] / 1e6);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function checkThis(thisArg) {
|
||||
|
@ -151,7 +141,6 @@ export {
|
|||
clearInterval,
|
||||
clearTimeout,
|
||||
defer,
|
||||
opNow,
|
||||
refTimer,
|
||||
setImmediate,
|
||||
setInterval,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue