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
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