Skip to content

module: cache deserialized package scopes - #65812

Open
gurgunday wants to merge 1 commit into
nodejs:mainfrom
gurgunday:perf/module-cache-package-scopes
Open

module: cache deserialized package scopes#65812
gurgunday wants to merge 1 commit into
nodejs:mainfrom
gurgunday:perf/module-cache-package-scopes

Conversation

@gurgunday

Copy link
Copy Markdown
Member

ESM loading repeatedly deserializes the same package configuration when resolving package imports and determining the format of relative .js imports. Spreading the configuration invokes its lazy getters, reparsing the imports and exports maps on each lookup

Cache the deserialized configuration by package.json path and reuse it when the serialized fields are unchanged. Each lookup still calls the existing loader method, so live VFS changes and errors remain visible. VFS unmounting clears the cache, and callers continue to receive separate result wrappers.

                                                     confidence   improvement   accuracy (*)    (**)   (***)
module/package-scope-config.js n=10000 entries=0     ***            +83.33 %   ±3.12%  ±4.34%  ±6.08%
module/package-scope-config.js n=10000 entries=20    ***           +207.93 %   ±5.72%  ±8.03%  ±11.37%
module/package-scope-config.js n=10000 entries=200   ***          +2494.96 %   ±59.83%  ±85.90%  ±126.23%
module/package-scope-config.js n=10000 entries=1000  ***          +3577.25 %   ±67.32%  ±96.71%  ±142.26%

Measured on an Apple M5 Pro. Inspired by/continues the work of #60425.

Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day>
Assisted-by: Codex
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. labels Sep 5, 2026
@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.18%. Comparing base (ad67159) to head (06b6f9a).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65812      +/-   ##
==========================================
+ Coverage   90.14%   90.18%   +0.03%     
==========================================
  Files         769      770       +1     
  Lines      262968   264430    +1462     
  Branches    50060    50241     +181     
==========================================
+ Hits       237057   238466    +1409     
- Misses      16932    16973      +41     
- Partials     8979     8991      +12     
Files with missing lines Coverage Δ
lib/internal/modules/package_json_reader.js 99.31% <100.00%> (+0.03%) ⬆️

... and 30 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants