Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/short-stamps-throw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

do not use performance.timeOrigin and calculate origins lazily
11 changes: 6 additions & 5 deletions packages/effect/src/internal/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -5824,7 +5825,7 @@ const processOrPerformanceNow = (function() {
if (!processHrtime) {
return performanceNowNanos
}
const origin = performanceNowNanos() - processHrtime.bigint()
const origin = (BigInt(Date.now()) * BigInt(1e6)) - processHrtime.bigint()
return () => origin + processHrtime.bigint()
})()

Expand Down
Loading