-
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 |
@@ -100,10 +100,18 @@ const BindingData::PackageConfig* BindingData::GetPackageJSON( | |||
return &cache_entry->second; | |||
} | |||
|
|||
if (!binding_data->missing_package_configs_.contains(path.data())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!binding_data->missing_package_configs_.contains(path.data())) { | |
if (binding_data->missing_package_configs_.contains(std::string(path))) { |
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
.