Skip to content

fix(pnp): cache package manifest lookups - #7259

Open
the-spyke wants to merge 1 commit into
yarnpkg:masterfrom
the-spyke:fix/pnp-package-json-cache
Open

fix(pnp): cache package manifest lookups#7259
the-spyke wants to merge 1 commit into
yarnpkg:masterfrom
the-spyke:fix/pnp-package-json-cache

Conversation

@the-spyke

Copy link
Copy Markdown

What's the problem this PR addresses?

Fixes the issue of excess file system operations while resolving the loaded file type (whether it is CJS or ESM).

Resolves #7258

...

How did you fix it?

Added a simple Map to cache both positive and negative package.json lookups. As an additional measure to lower memory consumption I cache only the type field, because the rest are not used by the consumers.

In my reproduction repo the number of syscalls went from 1,202 to just 6.

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

Cache both present and missing package manifests while determining module
formats. This avoids repeating filesystem lookups for every loaded JavaScript
file, which is particularly expensive on bind-mounted filesystems.
@the-spyke
the-spyke marked this pull request as ready for review August 15, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug?]: PnP ESM loader does not cache package.json scope lookups, causing O(files × directory depth) filesystem calls

1 participant