Repository navigation
Opt-in hard-link/reflink cache restore to avoid writing every cached output twice #37208
jlapenna
started this conversation in
Feature Requests
Replies: 1 comment
|
+1, with a second use case: the local edit loop, not CI. Setup: Windows 11 24H2 (build 26100). Workspace and Problem: every edit is a cache miss, so Measured (median of 3 runs,
What would help here:
Happy to test a branch on Windows/ReFS. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
Every cached output is written to disk twice, once into the local cache directory and once into the workspace. On ephemeral CI runners, where the local cache is discarded when the job ends, the first copy is almost pure write volume. Could Nx offer an opt-in restore mode that hard-links (or reflinks, where the filesystem supports it) instead of copying?
What happens today (nx 23.2.1)
remoteCache.retrieve(hash, cacheDirectory)extracts the artifact into<cacheDirectory>/<hash>/, thencopyFilesFromCache(nativecopy_dir_allinpackages/nx/src/native/cache/file_ops.rs) copies each file into the workspace.put()copies the task's outputs into<cacheDirectory>/<hash>/, andremoteCache.store()uploads from there.Measured: restoring one Node bundle target from a self-hosted remote cache into an empty
NX_CACHE_DIRECTORYon Linux/ext4:Why it matters
On our self-hosted CI fleet (ephemeral Docker runners, Nx remote cache), dependency installs are already metadata-only after other fixes. The remaining per-job disk writes are dominated by build outputs that Nx writes twice. Across the fleet that is hundreds of GB per day onto consumer NVMe drives, and SMART wear is climbing measurably. Keeping the cache in RAM isn't an option for memory-bound runners.
Proposal
An opt-in setting, for example
NX_CACHE_OUTPUT_MODE=copy|hardlink|reflink|auto(or annx.jsonoption), used on restore and optionally when storing:reflink/auto: useFICLONE/copy_file_rangeclone semantics where the filesystem supports them (XFS, btrfs, APFS clonefile). Blocks are shared until written, so this is safe by construction.hardlink: when the cache directory and the workspace are on the same filesystem, link instead of copying. It's opt-in because a tool that modifies outputs in place would also modify the cache entry; making cache files read-only would turn that into an error instead of silent corruption.copy.This touches the same code path as #37090, and #37085 (which parallelizes
copy_dir_all); a link or clone mode would compose with that work.Happy to provide more measurements or test a branch.
All reactions