Skip to content

fix(core): enable V8 module compilation cache in bin/nx.ts#35603

Open
FrozenPandaz wants to merge 1 commit intonrwl:masterfrom
FrozenPandaz:speed-nx-compile-cache
Open

fix(core): enable V8 module compilation cache in bin/nx.ts#35603
FrozenPandaz wants to merge 1 commit intonrwl:masterfrom
FrozenPandaz:speed-nx-compile-cache

Conversation

@FrozenPandaz
Copy link
Copy Markdown
Contributor

@FrozenPandaz FrozenPandaz commented May 6, 2026

Current Behavior

Every nx invocation re-parses and re-compiles the same JS modules from disk. Node 22.8+ ships an opt-in V8 cache for compiled bytecode (require('module').enableCompileCache()), but bin/nx.ts doesn't enable it.

⚠️ This is not the same as the v8-compile-cache npm package that was previously used in nx and removed in #20454 due to ESM incompatibility (Invalid host options error). The npm package was a userspace Module.prototype._compile monkey-patch and famously broke when ESM modules were loaded. The Node 22.8 built-in is implemented inside Node's loader and was designed specifically to support both CJS and ESM cleanly. It does not have the bug that motivated #20454.

Expected Behavior

Call enableCompileCache() at the top of bin/nx.ts so the cached bytecode is reused on subsequent runs. The optional chaining (?.) plus try/catch make it a no-op on older Node versions, and the cache itself is a no-op on the first run — every run after that pays only the cached-bytecode load instead of full parse+compile.

Cache files live in Node's default location (os.tmpdir()/node-compile-cache) and Node manages them automatically. Cache entries are keyed on source mtime+size and Node version, so they invalidate automatically when source changes or the user upgrades Node.

Measured on a hot-cache run-many --parallel 10 over 5 next.js apps:

median wall time
before 210ms
after 200ms

Related Issue(s)

Fixes #

Node 22.8+ ships an opt-in cache for compiled JS modules. Calling
`enableCompileCache()` at the top of bin/nx.ts skips the parse +
compile step for nx's JS modules on subsequent CLI invocations.

The optional chaining + try/catch makes it a no-op on older Node
versions, and the cache itself is a no-op on the first run; every
run after that pays only the cached-bytecode load.

Hot-cache run-many --parallel 10 over 5 next.js apps:
  before: 210ms median wall time
  after:  200ms median wall time
@FrozenPandaz FrozenPandaz requested a review from a team as a code owner May 6, 2026 20:57
@FrozenPandaz FrozenPandaz requested a review from leosvelperez May 6, 2026 20:57
@netlify
Copy link
Copy Markdown

netlify Bot commented May 6, 2026

👷 Deploy request for nx-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 01e52af

@netlify
Copy link
Copy Markdown

netlify Bot commented May 6, 2026

👷 Deploy request for nx-dev pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 01e52af

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented May 6, 2026

View your CI Pipeline Execution ↗ for commit 01e52af

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 22m 30s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 17s View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 25s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 7s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-07 02:00:58 UTC

Copy link
Copy Markdown
Contributor

@nx-cloud nx-cloud Bot left a comment

Choose a reason for hiding this comment

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

Important

At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.

Nx Cloud has identified a possible root cause for your failed CI:

We identified this failure as an environment issue unrelated to the PR's changes. The e2e test cannot install @angular-devkit/core@21.2.10 because that version has not yet been published to the npm registry (latest available is 21.2.9). No action is needed on our end — the failure will resolve once the Angular team publishes the missing package version.

No code changes were suggested for this issue.

You can trigger a rerun by pushing an empty commit:

git commit --allow-empty -m "chore: trigger rerun"
git push

Nx Cloud View detailed reasoning on Nx Cloud ↗

🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.


🎓 Learn more about Self-Healing CI on nx.dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant