Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use native performance object in Node 18 #38

Merged
merged 3 commits into from Jul 4, 2022
Merged

Conversation

nolanlawson
Copy link
Owner

Fixes #17

@nolanlawson
Copy link
Owner Author

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.getEntriesByName &&
perf.getEntriesByType &&
perf.clearMeasures
perf.clearMarks &&
perf.clearMeasures &&
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@nolanlawson nolanlawson merged commit 4933c46 into master Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Node.js Performance Timing API
1 participant