Skip to content

vm: allow createCachedData() after module evaluation - #67508

Open
magurotuna wants to merge 1 commit into
nodejs:mainfrom
magurotuna:vm-createcacheddata-after-eval
Open

magurotuna wants to merge 1 commit into
nodejs:mainfrom
magurotuna:vm-createcacheddata-after-eval

Conversation

@magurotuna

Copy link
Copy Markdown

sourceTextModule.createCachedData() throws ERR_VM_MODULE_CANNOT_CREATE_CACHED_DATA if the module is already evaluated. This check came from #31278, which matched a V8 check at that time. V8 removed its check in https://crrev.com/c/2504256 in Nov 2020, but Node has not caught up with it. So this PR allows the call to createCachedData() when the status is 'evaluated'. The call still throws while the module is evaluating and after the evaluation failed.

This will help speed up the vm pools of Vitest. A code cache created after evaluation can also contain the functions that V8 compiled lazily, so a module that uses it can compile less. A Vitest prototype that uses cached data after evaluation in subsequent test files took 12-24% less wall-clock time on a 500-file benchmark.

I used an AI coding assistant to help write the patch and the tests. I reviewed them.

Refs: https://chromium-review.googlesource.com/c/v8/v8/+/2504256
Refs: https://chromium-review.googlesource.com/c/v8/v8/+/8811778

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/vm

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. errors Issues and PRs related to JavaScript errors originating in Node.js core. needs-ci PRs that need a full CI run. vm Issues and PRs related to the vm subsystem. labels Nov 16, 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.

sourceTextModule.createCachedData() threw
ERR_VM_MODULE_CANNOT_CREATE_CACHED_DATA after the module was
evaluated. V8 removed this restriction in 2020. A code cache
that is created after evaluation can also contain the functions
that V8 compiled lazily during the evaluation, so a new module
that uses this code cache can compile less.

Allow the call after the module has been evaluated. The call
still throws while the module is evaluating, and after the
evaluation of the module failed.

Assisted-by: claude:opus-5.5
Signed-off-by: Yusuke "YT" Tanaka <ytanaka@cloudflare.com>
@magurotuna
magurotuna force-pushed the vm-createcacheddata-after-eval branch from 2f22f01 to ad44309 Compare November 16, 2026 07:43
@magurotuna
magurotuna marked this pull request as ready for review November 16, 2026 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. errors Issues and PRs related to JavaScript errors originating in Node.js core. needs-ci PRs that need a full CI run. vm Issues and PRs related to the vm subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants