fix: use native performance object in Node 18#38
Conversation
|
The fix we want to detect in Node is this one: nodejs/node#42032 But it's not observable, so we detect this slightly later fix: nodejs/node#42725 This is probably good enough for marky. There's no huge advantage right now (AFAICT) of using Node's built-in performance timeline, but hey, maybe someday they'll have a great debugger or something that takes advantage of native marks/measures. |
| perf.getEntriesByType && | ||
| perf.clearMeasures | ||
| perf.clearMarks && | ||
| perf.clearMeasures && |
There was a problem hiding this comment.
Seems prudent to check for every API we might use, and not rely on measure existing if mark exists, and clearMarks existing if clearMeasures exists.
| : nowForNode | ||
| export default perf && perf.now | ||
| ? () => perf.now() | ||
| : process.browser ? () => Date.now() : nowPolyfillForNode |
There was a problem hiding this comment.
Could probably get a microsecond perf boost from doing const now = perf.now.bind(perf), but meh. I don't want to rely on bind, or on now() working without the proper this, etc.
Fixes #17