Skip to content

sea: support code cache for ESM entrypoint in SEA#62158

Open
joyeecheung wants to merge 1 commit intonodejs:mainfrom
joyeecheung:esm-sea-code-cache
Open

sea: support code cache for ESM entrypoint in SEA#62158
joyeecheung wants to merge 1 commit intonodejs:mainfrom
joyeecheung:esm-sea-code-cache

Conversation

@joyeecheung
Copy link
Member

@joyeecheung joyeecheung commented Mar 8, 2026

The initial support for ESM entrypoint in SEA didn't support code cache. This patch implements that by following a path similar to how code cache in CJS SEA entrypoint is supported: at build time we generate the code cache from C++ and put it into the sea blob, and at runtime we consume it via a special case in compilation routines - for CJS this was
CompileFunctionForCJSLoader, in the case of SourceTextModule, it's in Module::New.

Refs: #61813

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/single-executable
  • @nodejs/vm

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. single-executable Issues and PRs related to single-executable applications labels Mar 8, 2026
// in the SEA code. Support it.
// Refs: https://github.com/nodejs/node/pull/48191#discussion_r1213271430
// TODO(joyeecheung): this likely has been fixed by
// https://chromium-review.googlesource.com/c/v8/v8/+/5401780 - add a test
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that this should already be fixed - and locally it works. But since it was talking about the CommonJS case I think it's out of scope of this PR, so I only left a TODO.

The initial support for ESM entrypoint in SEA didn't support
code cache. This patch implements that by following a path
similar to how code cache in CJS SEA entrypoint is supported:
at build time we generate the code cache from C++ and put it
into the sea blob, and at runtime we consume it via a special
case in compilation routines - for CJS this was
CompileFunctionForCJSLoader, in the case of SourceTextModule,
it's in Module::New.
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@codecov
Copy link

codecov bot commented Mar 8, 2026

Codecov Report

❌ Patch coverage is 80.35714% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.65%. Comparing base (724ef8e) to head (57e7b9f).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/node_sea.cc 78.12% 3 Missing and 4 partials ⚠️
src/module_wrap.cc 83.33% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62158      +/-   ##
==========================================
- Coverage   89.66%   89.65%   -0.01%     
==========================================
  Files         676      676              
  Lines      206543   206571      +28     
  Branches    39542    39552      +10     
==========================================
+ Hits       185193   185202       +9     
- Misses      13475    13484       +9     
- Partials     7875     7885      +10     
Files with missing lines Coverage Δ
src/module_wrap.cc 74.32% <83.33%> (+0.08%) ⬆️
src/node_sea.cc 89.53% <78.12%> (-0.18%) ⬇️

... and 34 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.

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 9, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 9, 2026
@nodejs-github-bot
Copy link
Collaborator

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++. needs-ci PRs that need a full CI run. single-executable Issues and PRs related to single-executable applications

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants