Skip to content

module: produce the compile cache after execution - #8

Draft
maschwenk wants to merge 1 commit into
base-main-67e45e4afrom
compile-cache-after-execution
Draft

maschwenk wants to merge 1 commit into
base-main-67e45e4afrom
compile-cache-after-execution

Conversation

@maschwenk

@maschwenk maschwenk commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

upstream candidate for nodejs/node, one commit on main 67e45e4. the v26 version with everything in it is

this is the cut down one. the compile cache serializes a module right after compiling it, so the cache only has the top level and every function that runs gets compiled again from source in every process. this keeps the compiled wrapper fn / module script of a module that missed the cache and serializes it again at exit or module.flushCompileCache(), keeps the compile-time cache if thats bigger (v8 flushes eagerly compiled fns that havent run for ~3 min), and never replaces a cache file with a smaller one unless v8 rejected it

left out on purpose: the gc checkpoint, refreshing caches that were accepted, all the env knobs, and freeing consumed buffers (that one is its own branch). no new options

warm cache, 30 paired runs on one graviton box vs main:
• tsc -p small project 366 → 300 ms (−18%)
• eslint on a small project 237 → 205 ms (−13%)
• loading webpack + babel + prettier + eslint + typescript 251 → 217 ms (−14%)
• npm --version 69 → 61 ms

tradeoff: a short command reading a cache that a longer one wrote pays to deserialize stuff it never calls, tsc --version after tsc -p is 61 → 75 ms. cold runs (the ones writing the cache) are 3-5% slower and warm max rss is up ~4-5% on tsc and eslint. tsc, eslint and npm all call module.enableCompileCache() themselves so their users get this by default

before it goes upstream it needs my signoff, and a rebase if nodejs/node PR 67120 (no compile cache while coverage is collected) lands first

The module compile cache serializes the V8 code cache of a module
right after compiling it, before it runs. V8 compiles functions
lazily, so that cache only holds the top-level code, and every
function the module calls is compiled again from source in each
process that loads it from the cache.

For a CommonJS or ES module that missed the cache, keep the compiled
wrapper function or module script, and serialize the cache again when
it is written at exit or by module.flushCompileCache(), when it also
holds the functions that ran. The cache produced at compilation is
kept if it is larger: V8 flushes the bytecode of functions that have
not run for a while, so a long-running process can lose eagerly
compiled functions from the later one. Since the content of a cache
now depends on what ran, a cache file for the same code is only
replaced by a larger one, unless V8 rejected it.

Refs: nodejs#52696
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coder-task-generated Opened by a coding agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant