[unenv] Use the native workerd perf_hooks modules when available#10618
Merged
petebacondarwin merged 30 commits intomainfrom Mar 4, 2026
Merged
[unenv] Use the native workerd perf_hooks modules when available#10618petebacondarwin merged 30 commits intomainfrom
petebacondarwin merged 30 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: 1e825e1 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
d261cd5 to
80639b6
Compare
d725306 to
cbf9ae2
Compare
This comment was marked as outdated.
This comment was marked as outdated.
…lementation The local performance.ts and perf_hooks.ts duplicated unenv's code with minor typing and behavioral differences. Since unenv's globalThis.performance sniffing correctly falls back to the full polyfill on workerd (which lacks addEventListener), and the compat flag system handles the native transition, the local overrides are unnecessary.
The polyfill inclusion is now gated solely on the nodejs_perf_hooks_module flag, since the polyfill imports from node:perf_hooks and the native module is a superset of the global performance classes.
Co-authored-by: Victor Berchet <[email protected]>
Co-authored-by: Victor Berchet <[email protected]>
ac35054 to
1e825e1
Compare
vicb
approved these changes
Mar 4, 2026
Contributor
vicb
left a comment
There was a problem hiding this comment.
Oops, was not actually approved for some reason...
Contributor
Author
Just the new codeowners-plus action dismissing reviews - we have now turned that off |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, the unenv-preset always used a polyfill for perf_hooks, which was provided in the unenv libray. This polyfill used sniffing of the
performance.addEventListenermethod to determine if the environment supported the perf_hooks API natively, and if so, it would use the native implementation.However, now that the native
performanceobject has been updated to provide stubs for many of these methods, the sniffing approach no longer works.This change moves the perf_hooks polyfill into the unenv-preset package, and removes the sniffing logic. The decision whether to use the native or polyfill implementation is now made based on whether the
enable_nodejs_perf_hooks_moduleflag is set.There are two compat flags of note:
enable_global_performance_classes("class") - only enables some standard performance classes and can be used without nodejs_compat.enable_nodejs_perf_hooks_module("module") - enables node:perf_hooks and also ensures that the performance global classes are avaiable (regardless of theenable_global_performance_classesflag).