feat: add file_clone option for reflink-based disk cache#2640
Open
quake wants to merge 1 commit intomozilla:mainfrom
Open
feat: add file_clone option for reflink-based disk cache#2640quake wants to merge 1 commit intomozilla:mainfrom
quake wants to merge 1 commit intomozilla:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2640 +/- ##
==========================================
- Coverage 73.37% 72.91% -0.47%
==========================================
Files 68 69 +1
Lines 37338 37019 -319
==========================================
- Hits 27396 26991 -405
- Misses 9942 10028 +86 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add a new `file_clone` configuration option for disk cache that stores cache entries as uncompressed directory structures and uses APFS clonefile/reflink when restoring files on cache hit. Configuration: - `[cache.disk] file_clone = true` in config file - `SCCACHE_FILE_CLONE=true` environment variable - Default: disabled When enabled, cache entries are stored as directories containing raw object files instead of compressed ZIP archives. On cache hit, files are restored via reflink (copy-on-write clone), which is near-instantaneous and shares physical disk blocks with the cache. If the filesystem doesn't support reflink, the feature automatically falls back to the original compressed ZIP+zstd storage format. Key implementation details: - Mixed format reading: both compressed and uncompressed entries can be read regardless of current mode - Directory entries use a .sccache_dir_entry marker file for identification and as an atomic write-complete signal - LRU eviction is directory-aware (evicts entire directory entries) - Cache size is ~2.8x larger than compressed (expected for uncompressed) Uses the reflink-copy crate for cross-platform reflink support.
Author
|
@sylvestre I force pushed to resolve a windows unit test error, could you help to trigger workflow running again, thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a
file_cloneoption for the disk cache that stores cache entries as uncompressed files and restores them using filesystem reflinks (e.g.clonefile()on APFS orFICLONEon Linux).When supported by the filesystem, restored artifacts share underlying storage blocks with the cache entry, avoiding both decompression and physical data duplication on disk.
This mode is particularly useful for workflows with frequent
cargo clean+ rebuild cycles (for example when switching branches), where build artifacts are repeatedly restored from cache.Key points:
file_clone = truein[cache.disk]SCCACHE_FILE_CLONE=truefalsereflink-copy)Benchmark Results
Benchmarks were run on macOS (APFS) using three Rust projects:
Build Times
Build times are effectively identical across both modes.
This indicates that
file_clonedoes not materially change compile performance for typical Rust workloads.Cache Storage
As expected, storing entries uncompressed increases cache size (~2.8×).
Read and write latencies remain sub-millisecond in both modes.
Disk Usage on Cache Restore
During warm builds, ~650 MiB of artifacts were restored from the cache.
On APFS,
dfreported no additional disk usage, confirming that restored files share underlying storage blocks with the cache via reflink.For my local development workflow on a large project where I frequently switch branches and rebuild, this feature can reduce disk usage by tens of gigabytes. Since restored artifacts are reflinked from the cache instead of being fully copied, repeated cargo clean + rebuild cycles no longer multiply disk usage.
Tradeoffs
Notes
This feature is conceptually similar to the
file_cloneoption in ccache, which also leverages filesystem reflinks to avoid unnecessary data duplication.Related issues:
#1174
#1053