-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
module: implement NODE_COMPILE_CACHE for automatic on-disk code caching #52535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2486,6 +2486,34 @@ Any other value will result in colorized output being disabled. | |
| [`NO_COLOR`][] is an alias for `NODE_DISABLE_COLORS`. The value of the | ||
| environment variable is arbitrary. | ||
|
|
||
| ### `NODE_COMPILE_CACHE=dir` | ||
|
|
||
| <!-- YAML | ||
| added: REPLACEME | ||
| --> | ||
|
|
||
| > Stability: 1.1 - Active Development | ||
|
|
||
| When set, whenever Node.js compiles a CommonJS or a ECMAScript Module, | ||
| it will use on-disk [V8 code cache][] persisted in the specified directory | ||
| to speed up the compilation. This may slow down the first load of a | ||
| module graph, but subsequent loads of the same module graph may get | ||
| a significant speedup if the contents of the modules do not change. | ||
|
|
||
| To clean up the generated code cache, simply remove the directory. | ||
| It will be recreated the next time the same directory is used for | ||
| `NODE_COMPILE_CACHE`. | ||
|
|
||
| Compilation cache generated by one version of Node.js may not be used | ||
| by a different version of Node.js. Cache generated by different versions | ||
| of Node.js will be stored separately if the same directory is used | ||
| to persist the cache, so they can co-exist. | ||
|
|
||
| Caveat: currently when using this with [V8 JavaScript code coverage][], the | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When enabling NODE_COMPILE_CACHE and running The failed tests are all related to less precise coverage which is currently a known caveat of code cache + v8 native coverage collection (e.g. see #51672). So I just documented that a bit in the docs that users should not use the two together for now. I could spare some time later to fix it in V8, but I don't think it's a blocker for this PR because this feature is currently opt-in. User-land code caching can run into this problem too, and it's technically a V8 bug. |
||
| coverage being collected by V8 may be less precise in functions that are | ||
| deserialized from the code cache. It's recommended to turn this off when | ||
| running tests to generate precise coverage. | ||
|
|
||
| ### `NODE_DEBUG=module[,…]` | ||
|
|
||
| <!-- YAML | ||
|
|
@@ -3130,6 +3158,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12 | |
| [Source Map]: https://sourcemaps.info/spec.html | ||
| [Subresource Integrity]: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity | ||
| [V8 JavaScript code coverage]: https://v8project.blogspot.com/2017/12/javascript-code-coverage.html | ||
| [V8 code cache]: https://v8.dev/blog/code-caching-for-devs | ||
| [Web Crypto API]: webcrypto.md | ||
| [`"type"`]: packages.md#type | ||
| [`--allow-child-process`]: #--allow-child-process | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This description is very technical - I would use more layman terms for the first paragraph.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have specific suggestions? I don't want to make it sound too magical to avoid false advertisement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll do a follow up PR after this lands to not hold it but ideally something that focuses more on what it does and not the technical implementation