Skip to content

GetPackageJson internal binding should cache missing file results #56821

Closed as not planned

Description

@dmichon-msft

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.

Activity

  1. juanarbol commented on Jan 30, 2025

    @juanarbol
    Member

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

  2. github-actions commented on Jul 29, 2025

    @github-actions
    Contributor

    There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the never-stale Issues and PRs exempt from automated stale handling. label or close this issue if it should be closed. If not, the issue will be automatically closed 6 months after the last non-automated comment.
    For more information on how the project manages feature requests, please consult the feature request management document.

  3. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jul 29, 2025
  4. github-actions commented on Aug 29, 2025

    @github-actions
    Contributor

    There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

    For more information on how the project manages feature requests, please consult the feature request management document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions