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

GetPackageJson internal binding should cache missing file results #56821

Open
dmichon-msft opened this issue Jan 30, 2025 · 1 comment · May be fixed by #56834
Open

GetPackageJson internal binding should cache missing file results #56821

dmichon-msft opened this issue Jan 30, 2025 · 1 comment · May be fixed by #56834
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@dmichon-msft
Copy link

Version

22.13.1

Platform

Linux codespaces-e55842 6.5.0-1025-azure #26~22.04.1-Ubuntu SMP Thu Jul 11 22:33:04 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

node/src/node_modules.cc

What steps will reproduce the bug?

Loading multiple files in the same folder (that doesn't contain a package.json) will trigger NodeJS to attempt to read package.json in that folder once for each file, rather than caching that the file did not exist and skipping the syscall.

How often does it reproduce? Is there a required condition?

100% reproduction.

What is the expected behavior? Why is that the expected behavior?

This check:

node/src/node_modules.cc

Lines 106 to 108 in 82ac335

if (ReadFileSync(&package_config.raw_json, path.data()) < 0) {
return nullptr;
}

should cache the "missing file" response in the package json result cache, so that future checks for that package.json will return a "missing file" result early and skip the syscall.

What do you see instead?

For each and every file load within a given directory that does not contain a package.json, NodeJS is making a separate open syscall against the package.json path for that folder.

Additional information

This is a performance regression from Node 18, which cached "missing file" results in its package.json cache.

@juanarbol
Copy link
Member

juanarbol commented Jan 30, 2025

Hi! Thanks for the report. PRs are more than welcome.

@juanarbol juanarbol added the feature request Issues that request new features to be added to Node.js. label Jan 30, 2025
@github-project-automation github-project-automation bot moved this to Awaiting Triage in Node.js feature requests Jan 30, 2025
@dmichon-msft dmichon-msft linked a pull request Jan 30, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
Status: Awaiting Triage
Development

Successfully merging a pull request may close this issue.

2 participants