From 206cac855130a44d940b42f09257467e5ec6877a Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Tue, 23 Jun 2026 12:45:52 +1200 Subject: [PATCH 1/2] do not use performance.timeOrigin and calculate origins lazily --- .changeset/short-stamps-throw.md | 5 +++++ packages/effect/src/internal/effect.ts | 16 ++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 .changeset/short-stamps-throw.md diff --git a/.changeset/short-stamps-throw.md b/.changeset/short-stamps-throw.md new file mode 100644 index 0000000000..1948e67888 --- /dev/null +++ b/.changeset/short-stamps-throw.md @@ -0,0 +1,5 @@ +--- +"effect": patch +--- + +do not use performance.timeOrigin and calculate origins lazily diff --git a/packages/effect/src/internal/effect.ts b/packages/effect/src/internal/effect.ts index e11253c024..360f6d5cb2 100644 --- a/packages/effect/src/internal/effect.ts +++ b/packages/effect/src/internal/effect.ts @@ -5810,11 +5810,12 @@ const performanceNowNanos = (function() { const bigint1e6 = BigInt(1_000_000) if (typeof performance === "undefined" || typeof performance.now === "undefined") { return () => BigInt(Date.now()) * bigint1e6 - } else if (typeof performance.timeOrigin === "number" && performance.timeOrigin === 0) { - return () => BigInt(Math.round(performance.now() * 1_000_000)) } - const origin = (BigInt(Date.now()) * bigint1e6) - BigInt(Math.round(performance.now() * 1_000_000)) - return () => origin + BigInt(Math.round(performance.now() * 1_000_000)) + let origin: bigint + return () => { + origin ??= (BigInt(Date.now()) * bigint1e6) - BigInt(Math.round(performance.now() * 1_000_000)) + return origin + BigInt(Math.round(performance.now() * 1_000_000)) + } })() const processOrPerformanceNow = (function() { const processHrtime = @@ -5824,8 +5825,11 @@ const processOrPerformanceNow = (function() { if (!processHrtime) { return performanceNowNanos } - const origin = performanceNowNanos() - processHrtime.bigint() - return () => origin + processHrtime.bigint() + let origin: bigint + return () => { + origin ??= performanceNowNanos() - processHrtime.bigint() + return origin + processHrtime.bigint() + } })() /** @internal */ From 336fa1362e45c23cb10d683106bb9bc00599dab1 Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Tue, 23 Jun 2026 13:25:35 +1200 Subject: [PATCH 2/2] use Date.now for hrtime origin --- packages/effect/src/internal/effect.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/effect/src/internal/effect.ts b/packages/effect/src/internal/effect.ts index 360f6d5cb2..a78db737f0 100644 --- a/packages/effect/src/internal/effect.ts +++ b/packages/effect/src/internal/effect.ts @@ -5825,11 +5825,8 @@ const processOrPerformanceNow = (function() { if (!processHrtime) { return performanceNowNanos } - let origin: bigint - return () => { - origin ??= performanceNowNanos() - processHrtime.bigint() - return origin + processHrtime.bigint() - } + const origin = (BigInt(Date.now()) * BigInt(1e6)) - processHrtime.bigint() + return () => origin + processHrtime.bigint() })() /** @internal */