Skip to content

Commit 14e465a

Browse files
authored
Add custom zstd compression level (#2199)
* Add custom zstd compression level * docs for SCCACHE_CACHE_ZSTD_LEVEL * add zstd level test * docs for zstd level that warns new cache required * fix integration-test of zstd-compression-level
1 parent f571231 commit 14e465a

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

.github/workflows/integration-tests.yml

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,6 @@ jobs:
523523
shell: bash
524524
run: cat "$SCCACHE_ERROR_LOG"
525525

526-
527526
clang:
528527
runs-on: ubuntu-latest
529528
needs: build
@@ -576,7 +575,7 @@ jobs:
576575
${SCCACHE_PATH} --show-stats | grep -e "Cache hits\s*[1-9]"
577576
578577
hip:
579-
# Probably wouldn't matter anyway since we run in a container, but staying
578+
# Probably wouldn't matter anyway since we run in a container, but staying
580579
# close to the version is better than not.
581580
runs-on: ubuntu-22.04
582581
needs: build
@@ -646,7 +645,6 @@ jobs:
646645
647646
${SCCACHE_PATH} --show-stats | grep -e "Cache hits\s*[1-9]"
648647
649-
650648
gcc:
651649
runs-on: ubuntu-latest
652650
needs: build
@@ -691,7 +689,6 @@ jobs:
691689
692690
${SCCACHE_PATH} --show-stats | grep -e "Cache hits\s*[1-9]"
693691
694-
695692
autotools:
696693
runs-on: ubuntu-latest
697694
needs: build
@@ -846,3 +843,54 @@ jobs:
846843
run: |
847844
${SCCACHE_PATH} --show-stats
848845
${SCCACHE_PATH} --show-stats | grep -e "Cache hits\s*[1-9]"
846+
847+
zstd-compression-level:
848+
runs-on: ubuntu-latest
849+
needs: build
850+
851+
env:
852+
RUSTC_WRAPPER: /home/runner/.cargo/bin/sccache
853+
SCCACHE_DIR:
854+
CARGO_INCREMENTAL: "0"
855+
856+
steps:
857+
- uses: actions/download-artifact@v4
858+
with:
859+
name: integration-tests
860+
path: /home/runner/.cargo/bin/
861+
- name: Chmod for binary
862+
run: chmod +x ${SCCACHE_PATH}
863+
864+
- name: Clone repository
865+
uses: actions/checkout@v4
866+
867+
- name: Install rust
868+
uses: ./.github/actions/rust-toolchain
869+
with:
870+
toolchain: "stable"
871+
872+
- name: default-test-save
873+
run: |
874+
export SCCACHE_DIR=${PWD}/temp-test/zstd-level/default
875+
cargo build
876+
- name: default-stats-save
877+
run: ${SCCACHE_PATH} --show-stats
878+
- name: default-test-use
879+
run: |
880+
cargo clean && cargo build
881+
- name: default-stats-use
882+
run: ${SCCACHE_PATH} --show-stats
883+
- name: lv10-test-save
884+
run: |
885+
export SCCACHE_DIR=${PWD}/temp-test/zstd-level/10
886+
export SCCACHE_CACHE_ZSTD_LEVEL=10
887+
${SCCACHE_PATH} --stop-server > /dev/null
888+
cargo clean
889+
cargo build
890+
- name: lv10-stats-save
891+
run: ${SCCACHE_PATH} --show-stats
892+
- name: lv10-test-use
893+
run: |
894+
cargo clean && cargo build
895+
- name: lv10-stats-use
896+
run: ${SCCACHE_PATH} --show-stats

docs/Configuration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ configuration variables
133133
* `SCCACHE_MAX_FRAME_LENGTH` how much data can be transferred between client and server
134134
* `SCCACHE_NO_DAEMON` set to `1` to disable putting the server to the background
135135
* `SCCACHE_CACHE_MULTIARCH` to disable caching of multi architecture builds.
136+
* `SCCACHE_CACHE_ZSTD_LEVEL` to set zstd compression level of cache. the range is `1-22` and default is `3`.
137+
- For example, in `10`, it have about 0.9x size with about 1.6x time than default `3` (tested with compiling sccache code)
138+
- This option will only applied to newly compressed cache and don't affect existing cache.
139+
- If you want to be apply to all cache, you should reset cache and make new cache.
136140

137141
### cache configs
138142

src/cache/cache.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,12 @@ impl CacheWrite {
290290
self.zip
291291
.start_file(name, opts)
292292
.context("Failed to start cache entry object")?;
293-
zstd::stream::copy_encode(from, &mut self.zip, 3)?;
293+
294+
let compression_level = std::env::var("SCCACHE_CACHE_ZSTD_LEVEL")
295+
.ok()
296+
.and_then(|value| value.parse::<i32>().ok())
297+
.unwrap_or(3);
298+
zstd::stream::copy_encode(from, &mut self.zip, compression_level)?;
294299
Ok(())
295300
}
296301

0 commit comments

Comments
 (0)