-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Build Tooling: Optimize build by caching results #15967
Comments
A complication here is that one source file will have multiple output files, so it's not quite straight-forward to detect a cached result by the presence of a hash. A couple ideas:
|
Last week I started experimenting with an approach where we cache objects instead of files by serialising the object as a JSON string. You can see where I got over in the It's not finished as there were errors when you running the build. Still, if anyone would like to pick this up: go for it! The assumption I made that we will have to verify is that doing these
Thinking that we just recursively traverse the cache directory and delete files that are more than 3 months old. If traversal itself is too slow then we could only perform this operation when |
As written, are you assuming that we'd have multiple identical source files which could benefit from the memoization? I could also imagine just writing this as a file with the stringified JSON object, as an alternative to what I considered in my previous comment of a directory of files, where the keys in the JSON object are equivalent to files in a directory. Unclear whether this would have a performance difference, e.g. if a file system would be faster at copying a file than to parse JSON and write a new one from the object contents.
This makes sense, but I'm not sure when this would occur. For me, ideally it'd be some "fire and forget" (non-blocking) action which occurs after a build completes. There's various lifecycle steps like If it's not possible to use these as "non-blocking" (i.e. assuming the container shuts down after the build completes), maybe instead it's just a separate task of the build to do the cleanup, since presumably it wouldn't take long and could be done in parallel to other tasks. |
This isn't an explicit objective of what I wrote, no. We could add the path of the input file to the string that is hashed so that two identical source files using the same cache entry. I figured this isn't necessary though since, if two source files are identical, they will compile to the same result. |
Yeah, you're right that it's likely that a Perhaps something like this for an e.g. {
"src/example.js": {
"hash": "1a79a4d60de6718e8e5b326e338ae533",
"output": {
"build/example.js": ".cache/1a79a4d60de6718e8e5b326e338ae533.js",
"build/example.js.map": ".cache/1a79a4d60de6718e8e5b326e338ae533.js.map"
}
}
} |
I spent some time experimenting with this on Friday, and made some decent (but incomplete/buggy) progress. The work is currently reflected in the A few of my observations:
|
Previously: #15230 , #13124
As explored previously in #13124 and discussed in #15230, we may be able to benefit from improved build times by leveraging a persisted cache of previously-built artifacts.
Implementation Notes:
gitignore
d location, e.g.node_modules/.cache/gutenberg-build
orrequire( 'os' ).tmpdir()
(seebabel-loader
as prior art)BABEL_CACHE_DIRECTORY
override in Scripts: Optimize default Webpack configuration #14860The text was updated successfully, but these errors were encountered: