Skip to content

module: reduce memory retained by leaf ModuleJobs - #67398

Open
Uziniii wants to merge 1 commit into
nodejs:mainfrom
Uziniii:perf/esm-module-job-memory
Open

Uziniii wants to merge 1 commit into
nodejs:mainfrom
Uziniii:perf/esm-module-job-memory

Conversation

@Uziniii

@Uziniii Uziniii commented Nov 11, 2026 •

Copy link
Copy Markdown

Leaf ModuleJob instances without module requests now share a frozen empty array instead of allocating separate arrays for dependency tracking.

Modules with dependencies keep their existing mutable arrays. The unused importAttributes and isMain properties are no longer retained, while the constructor arguments remain unchanged.

Benchmark on lodash-es@4.17.21 with 30 alternating baseline/patched runs:

Binary Median heapUsed
Baseline 11,996,712 bytes (12.00 MB)
Patched 11,810,752 bytes (11.81 MB)

Result: -185,960 bytes (-0.186 MB, -1.55%).

A targeted benchmark with 20,000 leaf ESM modules showed -9.85% heapUsed; this is a focused microbenchmark, not a general Node.js gain.

The ESM test suite passes 245 tests. Three sandbox-related failures occur on both baseline and patched versions.

AI assistance was used to investigate the Git history, develop this change, and help draft this description. I reviewed and verified the code and take responsibility for the submitted change.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. labels Nov 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

Share empty dependency arrays for leaf ModuleJobs instead of allocating
separate arrays for each job. Remove unused per-job fields and avoid
retaining a default import attributes object when it is not provided.

Assisted-by: OpenCode
Signed-off-by: Uzini <43294422+Uziniii@users.noreply.github.com>
@Uziniii
Uziniii force-pushed the perf/esm-module-job-memory branch from 73be8cf to f498043 Compare November 11, 2026 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants