Skip to content

perf: use node: prefix to bypass require.cache call for builtins #14515

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

Closed
wants to merge 3 commits into from
Closed

perf: use node: prefix to bypass require.cache call for builtins #14515

wants to merge 3 commits into from

Conversation

Fdawgs
Copy link
Contributor

@Fdawgs Fdawgs commented Sep 12, 2023

Summary

Introduced as part of v16.0.0 and v14.18.0, this allows redundant require.cache calls to be bypassed for builtin modules, saving a few yoctoseconds.

See https://nodejs.org/api/modules.html#core-modules and discussion in nodejs/node repo regarding why require.cache calls are redundant for builtins.

Test plan

N/A

@netlify
Copy link

netlify bot commented Sep 12, 2023

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit ef5566d
🔍 Latest deploy log https://app.netlify.com/sites/jestjs/deploys/65049ec1dfc5fe000840bb49
😎 Deploy Preview https://deploy-preview-14515--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@SimenB
Copy link
Member

SimenB commented Sep 12, 2023

Is there some eslint rule we can use which forces (and autofixes) this?

@SimenB SimenB added this to the Jest 30 milestone Sep 12, 2023
@SimenB
Copy link
Member

SimenB commented Sep 12, 2023

Type error will probably be fixed by updating from node 14 types to node 16 (which will be done for Jest 30 - I'll start landing breaking changes next week)

@SimenB
Copy link
Member

SimenB commented Sep 13, 2023

@Fdawgs
Copy link
Contributor Author

Fdawgs commented Sep 13, 2023

There is https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-node-protocol.md at least

Probably something that should be rolled into https://github.com/eslint-community/eslint-plugin-n, are you happy for me to add the unicorn plugin in in the meantime with that rule enabled?

@SimenB
Copy link
Member

SimenB commented Sep 14, 2023

I've landed the unicorn plugin on main now, so feel free to activate the rule 🙂

Lots of test failures here. Also, we have some tests that explicitly use one or the other to ensure Jest's own resolver handles both correctly. So in some files we'll need to disable the rule

@Fdawgs
Copy link
Contributor Author

Fdawgs commented Sep 14, 2023

Cheers @SimenB, should be able to revisit this in the next few days.

@SimenB
Copy link
Member

SimenB commented Sep 14, 2023

Great, thank you!

@Fdawgs Fdawgs marked this pull request as draft September 15, 2023 08:41
@Fdawgs
Copy link
Contributor Author

Fdawgs commented Sep 15, 2023

Also, we have some tests that explicitly use one or the other to ensure Jest's own resolver handles both correctly. So in some files we'll need to disable the rule

@SimenB could you point me to a file that does this as an example, please?

@SimenB
Copy link
Member

SimenB commented Sep 15, 2023

Might be it just matters here

import dns from 'dns';
// the point here is that it's the node core module
// eslint-disable-next-line no-restricted-imports
import {readFileSync} from 'fs';
import {createRequire} from 'module';
import prefixDns from 'node:dns';
import {dirname, resolve} from 'path';
import {fileURLToPath} from 'url';

I doubt unit tests of isCoreModule is affected.

You might hit #14297 tho

@Fdawgs
Copy link
Contributor Author

Fdawgs commented Sep 15, 2023

Going to be doing this piecemeal, package-by-package, just so I don't miss anything, so apologies in advance!

@SimenB
Copy link
Member

SimenB commented Sep 15, 2023

No need to apologise! I'm super grateful you're taking the time to do this 🙂

@SimenB
Copy link
Member

SimenB commented Sep 20, 2023

New version of @types/node has landed on master, which should resolve the TS error

@Fdawgs
Copy link
Contributor Author

Fdawgs commented Sep 20, 2023

Thanks @SimenB, will revisit shortly. Was hitting #14297 at most points though. :(

@SimenB
Copy link
Member

SimenB commented Sep 20, 2023

Yeah, it might make sense to fix that before changing our own references...

@Fdawgs Fdawgs closed this by deleting the head repository Nov 2, 2023
@SimenB
Copy link
Member

SimenB commented Nov 2, 2023

fair 😀

@Fdawgs
Copy link
Contributor Author

Fdawgs commented Nov 2, 2023

fair 😀

Disappearing for a bit and probably won't be back until Feb next year. This will no doubt be mighty out of date by then so thought i'd just nuke it and return to it when I can.

@SimenB
Copy link
Member

SimenB commented Nov 2, 2023

Enjoy your time off! 😃

I genuinely meant that it's fair to abandon this - it's very chore-y and onerous 🙂 I realize it might've come off as sarcastic 😅

Copy link

github-actions bot commented Dec 3, 2023

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants