let supported: boolean
let perf: Performance
+// To avoid the overhead of repeatedly calling Date.now(), we cache
+// and use the same timestamp for all event listeners attached in the same tick.
+let cachedNow: number = 0
+const p = /*@__PURE__*/ Promise.resolve()
+const getNow = () =>
+ cachedNow ||
+ (p.then(() => (cachedNow = 0)),
+ (cachedNow = isSupported() ? perf.now() : Date.now()))
+
/**
* @internal
*/
}
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
- devtoolsPerfStart(instance, type, isSupported() ? perf.now() : Date.now())
+ devtoolsPerfStart(instance, type, getNow())
}
}
}
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
- devtoolsPerfEnd(instance, type, isSupported() ? perf.now() : Date.now())
+ devtoolsPerfEnd(instance, type, getNow())
}
}