-
-
Notifications
You must be signed in to change notification settings - Fork 32k
src: add an option to make compile cache path relative #58797
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
base: main
Are you sure you want to change the base?
Conversation
Adds an option (NODE_COMPILE_CACHE_RELATIVE_PATH) for the built-in compile cache to encode the hashes with relative file paths. On enabling the option, the source directory along with cache directory can be bundled and moved, and the cache continues to work. When enabled, paths encoded in hash are relative to compile cache directory.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #58797 +/- ##
==========================================
- Coverage 90.16% 90.09% -0.07%
==========================================
Files 636 640 +4
Lines 188061 188341 +280
Branches 36899 36927 +28
==========================================
+ Hits 169561 169692 +131
- Misses 11245 11363 +118
- Partials 7255 7286 +31
🚀 New features to boost your workflow:
|
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.
Can you add some integration to module.enableCompileCache()
as well? I think having it in options bag when the first argument is an object might work well enough. The path can be options.path
in that case.
@@ -3181,6 +3181,10 @@ added: v22.1.0 | |||
Enable the [module compile cache][] for the Node.js instance. See the documentation of | |||
[module compile cache][] for details. | |||
|
|||
### `NODE_COMPILE_CACHE_RELATIVE_PATH=0` |
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 wonder if "relative" is more of an implementation detail, what we really want to allow is "portable" compile cache (i.e. you can move the code and the compile cache to a different base directory, the cache will still be hit as long as they maintain the same directory structure) So maybe NODE_COMPILE_CACHE_PORTABLE=0
would be more intuitive and we can explain about the directory structure with an example in the docs.
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.
Also, please add some documentation to the Module compile cache
section in module.md as well.
if (use_relative_ && IsAbsoluteFilePath(file_path)) { | ||
// Normalise the paths to ensure they are consistent. | ||
std::string normalised_file_path = NormalisePath(file_path); | ||
std::string normalised_cache_dir = |
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 is something we can just compute once and store in the CompileCacheHandler instance. This is currently being repeatedly computed for every path match even though it's the same every time.
// This tests NODE_COMPILE_CACHE works with the NODE_COMPILE_CACHE_RELATIVE_PATH | ||
// environment variable. | ||
|
||
require('../common'); |
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.
Can you add some tests for module.getCompileCacheDir()
as well? I think it should return a relative path (from process.cwd()
?) in that case.
Adds an option (NODE_COMPILE_CACHE_RELATIVE_PATH) for the built-in compile cache to encode the hashes with relative file paths. On enabling the option,
the source directory along with cache directory can be bundled and moved, and the cache continues to work.
When enabled, paths encoded in hash are relative to compile cache directory.
Fixes: #58755
Thanks @joyeecheung for all the help :)