-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
src: cache negative results in GetPackageJSON #56834
base: main
Are you sure you want to change the base?
Conversation
This change ensures that GetPackageJSON caches which folders do *not* contain a package.json, to prevent excessive file system probing.
What happens if a package.json file is created after this is cached? |
The same thing that happens if you change the content of an existing package.json file after it gets read (and cached). The state of the world as of the first read of the folder is preserved. |
How does one clear the cache, then, after making a change? |
Usually by shutting down and restarting the process, since this cache is used during module loading. |
Missing package.json files were cached in Node <= 20:
As near as I can tell, this behavior change was simply an oversight when migrating Node <= 20 also does not provide any means for cache entries regarding |
Fixed incorrect negation Co-authored-by: Yagiz Nizipli <yagiz@nizipli.com>
Hmm...as a follow up, should we consider making it possible to clear both the missing and found caches at runtime to allow for hot reloading of these? Would that even make sense? Not something to worry about in this PR but something worth exploring separately. |
The entries in the cache will be there because they impacted the loading of already-loaded modules, so you could get some really weird results if we purge the cache and not all of the modules that were loaded from folders whose package.json files were checked. Ultimately, I think any runtime change that affects resolution of already-loaded code is heavily in the "use at your own peril" category. I think we'd be better served ensuring the hits and misses also find their way into the metadata for |
It looks like build is failing on CI |
Appears to need #56846 to land... |
Fixes #56821
Ensure that
GetPackageJSON
caches whichpackage.json
files do not exist, not just the contents of the ones that do. In packages with at least one subfolder, it is normal for most folders in a package not to contain apackage.json
file, so this will significantly reduce the number of file system reads performed duringGetNearestParentPackageJSON
.