module: do not split a portable compile cache by uid - #65293
Conversation
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65293 +/- ##
==========================================
+ Coverage 90.32% 90.34% +0.01%
==========================================
Files 751 751
Lines 249960 250332 +372
Branches 47204 47316 +112
==========================================
+ Hits 225774 226160 +386
- Misses 15564 15566 +2
+ Partials 8622 8606 -16
🚀 New features to boost your workflow:
|
A portable compile cache is meant to be reused wherever the same module layout is found, which includes being generated once (at build time, say) and shipped read-only with an application for whoever runs it. On platforms with uids the cache subdirectory is suffixed with the uid of the user who created it, so such a cache is only ever found by that one user. Omit the suffix in portable mode: a user who cannot write to the directory still reads it, and a failed write is only a cache miss. Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
2201240 to
cdb9ccf
Compare
|
I like this. Could it be used to speed up startup of servers deployed in Docker containers? Like maybe I build the cache when I build the Docker image, and when the container starts up it should start a little faster? |
|
@GeoffreyBooth yep that's the idea. you could build the cache during docker build with the missing bit for read-only images is #65302 which just stops node from trying to write into the cache directory when it can't |
|
That sounds great. Once all the pieces land we should add a Docker example in the docs somewhere. |
|
@GeoffreyBooth any idea what's up with the commit queue? |
A portable compile cache is meant to be reused wherever the same module layout is found. One shape of that is a cache generated once, at build time, and shipped read-only with an application for whoever runs it. On platforms with uids the cache subdirectory is suffixed with the uid of the user who created it (
$NODE_VERSION-$ARCH-$CACHE_DATA_VERSION_TAG-$UID), so such a cache is only ever found by that one user; the split exists so users sharing a writable directory do not trip over each other's file permissions.This omits the uid suffix in portable mode only. A user who cannot write to the directory still reads it, and a failed write is only a cache miss (
Persistalready logs and skips a temp file it cannot create). Non-portable caches keep the suffix.Docs updated for
portableandNODE_COMPILE_CACHE_PORTABLE;test-compile-cache-api-portablenow asserts the tag directory name.Context: an Electron application generating its main-process cache at package time and shipping it beside its
app.asar(module.enableCompileCache({ directory, portable: true })at launch); measured on that app, the shipped cache roughly halves the launch bundle's load time, but with the uid in the tag it is only found by users whose uid matches the build machine's.