Repository navigation
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 itleft 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 -psmall 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 --version69 → 61 mstradeoff: a short command reading a cache that a longer one wrote pays to deserialize stuff it never calls,
tsc --versionaftertsc -pis 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 callmodule.enableCompileCache()themselves so their users get this by defaultbefore it goes upstream it needs my signoff, and a rebase if
nodejs/nodePR 67120 (no compile cache while coverage is collected) lands first