Skip to content
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

Add custom zstd compression level #2199

Merged
merged 6 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 52 additions & 4 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ jobs:
shell: bash
run: cat "$SCCACHE_ERROR_LOG"


clang:
runs-on: ubuntu-latest
needs: build
Expand Down Expand Up @@ -576,7 +575,7 @@ jobs:
${SCCACHE_PATH} --show-stats | grep -e "Cache hits\s*[1-9]"

hip:
# Probably wouldn't matter anyway since we run in a container, but staying
# Probably wouldn't matter anyway since we run in a container, but staying
# close to the version is better than not.
runs-on: ubuntu-22.04
needs: build
Expand Down Expand Up @@ -646,7 +645,6 @@ jobs:

${SCCACHE_PATH} --show-stats | grep -e "Cache hits\s*[1-9]"


gcc:
runs-on: ubuntu-latest
needs: build
Expand Down Expand Up @@ -691,7 +689,6 @@ jobs:

${SCCACHE_PATH} --show-stats | grep -e "Cache hits\s*[1-9]"


autotools:
runs-on: ubuntu-latest
needs: build
Expand Down Expand Up @@ -846,3 +843,54 @@ jobs:
run: |
${SCCACHE_PATH} --show-stats
${SCCACHE_PATH} --show-stats | grep -e "Cache hits\s*[1-9]"

zstd-compression-level:
runs-on: ubuntu-latest
needs: build

env:
RUSTC_WRAPPER: /home/runner/.cargo/bin/sccache
SCCACHE_DIR:
CARGO_INCREMENTAL: "0"

steps:
- uses: actions/download-artifact@v4
with:
name: integration-tests
path: /home/runner/.cargo/bin/
- name: Chmod for binary
run: chmod +x ${SCCACHE_PATH}

- name: Clone repository
uses: actions/checkout@v4

- name: Install rust
uses: ./.github/actions/rust-toolchain
with:
toolchain: "stable"

- name: default-test-save
run: |
export SCCACHE_DIR=${PWD}/temp-test/zstd-level/default
cargo build
- name: default-stats-save
run: ${SCCACHE_PATH} --show-stats
- name: default-test-use
run: |
cargo clean && cargo build
- name: default-stats-use
run: ${SCCACHE_PATH} --show-stats
- name: lv10-test-save
run: |
export SCCACHE_DIR=${PWD}/temp-test/zstd-level/10
export SCCACHE_CACHE_ZSTD_LEVEL=10
${SCCACHE_PATH} --stop-server > /dev/null
cargo clean
cargo build
- name: lv10-stats-save
run: ${SCCACHE_PATH} --show-stats
- name: lv10-test-use
run: |
cargo clean && cargo build
- name: lv10-stats-use
run: ${SCCACHE_PATH} --show-stats
4 changes: 4 additions & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ configuration variables
* `SCCACHE_MAX_FRAME_LENGTH` how much data can be transferred between client and server
* `SCCACHE_NO_DAEMON` set to `1` to disable putting the server to the background
* `SCCACHE_CACHE_MULTIARCH` to disable caching of multi architecture builds.
* `SCCACHE_CACHE_ZSTD_LEVEL` to set zstd compression level of cache. the range is `1-22` and default is `3`.
- For example, in `10`, it have about 0.9x size with about 1.6x time than default `3` (tested with compiling sccache code)
- This option will only applied to newly compressed cache and don't affect existing cache.
- If you want to be apply to all cache, you should reset cache and make new cache.

### cache configs

Expand Down
7 changes: 6 additions & 1 deletion src/cache/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,12 @@ impl CacheWrite {
self.zip
.start_file(name, opts)
.context("Failed to start cache entry object")?;
zstd::stream::copy_encode(from, &mut self.zip, 3)?;

let compression_level = std::env::var("SCCACHE_CACHE_ZSTD_LEVEL")
.ok()
.and_then(|value| value.parse::<i32>().ok())
.unwrap_or(3);
zstd::stream::copy_encode(from, &mut self.zip, compression_level)?;
Ok(())
}

Expand Down
Loading