Skip to content

module: add a read-only mode to the compile cache - #65302

Open
codebytere wants to merge 1 commit into
nodejs:mainfrom
codebytere:compile-cache-read-only
Open

module: add a read-only mode to the compile cache#65302
codebytere wants to merge 1 commit into
nodejs:mainfrom
codebytere:compile-cache-read-only

Conversation

@codebytere

Copy link
Copy Markdown
Member

A compile cache generated ahead of time and shipped inside an application package should only ever be read: the package may be immutable (an Electron app.asar, a read-only image) or covered by an integrity check, and a cache directory that appears at run time next to shipped code is a surprise either way. Today enabling the cache always implies writing: the tag directory is created on enable, and every module without an accepted entry is serialized and persisted at exit or on flushCompileCache().

This adds readOnly to module.enableCompileCache() and NODE_COMPILE_CACHE_READONLY=1. With it, existing entries are looked up and loaded exactly as before; nothing is serialized into the in-memory store or written to disk, flushCompileCache() is a no-op, the write-permission check is skipped, and the cache directory is used as found rather than created, so enabling against a directory that does not exist fails (FAILED, with a message) instead of making one.

EnableOption becomes a small flag set (PORTABLE, READ_ONLY) since the two combine. Docs cover the option, the environment variable (cli.md, node.1) and a short section in module.md; test-compile-cache-api-readonly covers the missing-directory case, reading a previously generated cache without writing new entries, and the environment variable.

Context: same application as #65293 (an Electron app shipping its main-process cache in the package); review there asked that production launches never attempt writes.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Aug 15, 2026
@codebytere
codebytere force-pushed the compile-cache-read-only branch 2 times, most recently from 447fb62 to 133e37b Compare August 15, 2026 09:09
@codebytere
codebytere force-pushed the compile-cache-read-only branch from 133e37b to d57ec48 Compare August 16, 2026 18:30
A compile cache generated ahead of time and shipped inside an
application package should only ever be read: the package may be
immutable or covered by an integrity check, and a cache directory that
appears at run time would be a surprise. Add readOnly to
module.enableCompileCache() and NODE_COMPILE_CACHE_READONLY=1: existing
entries are loaded as before, nothing is serialized or persisted,
flushCompileCache() is a no-op, and the cache directory is used as found
rather than created, so enabling against a missing directory fails
instead of making one.

Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
@codebytere
codebytere force-pushed the compile-cache-read-only branch from d57ec48 to dc597d8 Compare August 16, 2026 18:31
@codebytere codebytere added request-ci Add this label to start a Jenkins CI on a PR. and removed needs-ci PRs that need a full CI run. labels Aug 16, 2026
@codecov

codecov Bot commented Aug 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.71014% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.13%. Comparing base (bc813a7) to head (dc597d8).
⚠️ Report is 40 commits behind head on main.

Files with missing lines Patch % Lines
src/compile_cache.cc 75.60% 5 Missing and 5 partials ⚠️
src/env.cc 62.50% 1 Missing and 2 partials ⚠️
src/node_modules.cc 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65302      +/-   ##
==========================================
- Coverage   90.32%   90.13%   -0.20%     
==========================================
  Files         751      752       +1     
  Lines      249960   251615    +1655     
  Branches    47204    47269      +65     
==========================================
+ Hits       225774   226783    +1009     
- Misses      15564    16174     +610     
- Partials     8622     8658      +36     
Files with missing lines Coverage Δ
lib/internal/modules/helpers.js 98.94% <100.00%> (+<0.01%) ⬆️
src/compile_cache.h 100.00% <100.00%> (ø)
src/node_modules.cc 80.14% <75.00%> (-0.10%) ⬇️
src/env.cc 85.17% <62.50%> (-0.24%) ⬇️
src/compile_cache.cc 79.43% <75.60%> (+0.34%) ⬆️

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

@codebytere
codebytere requested a review from Renegade334 August 16, 2026 20:23
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 17, 2026
@nodejs-github-bot

Copy link
Copy Markdown
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++. lib / src Issues and PRs related to general changes in the lib or src directory.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants