fix(ci): improve cache hit rate with shared-key and job-level sccache env#2324
Merged
fix(ci): improve cache hit rate with shared-key and job-level sccache env#2324
Conversation
rust-cache and sccache serve distinct layers: rust-cache covers registry downloads (~/.cargo/registry, ~/.cargo/git) while sccache covers compiled artifacts. With cache-targets=false they don't overlap. Primary fix: add shared-key so all jobs in the same workflow share one rust-cache entry instead of each creating an independent key. Without shared-key, every job misses the cache and re-downloads the full registry. - lint-clippy, build-tests: shared-key="ci" (same toolchain + feature set) - coverage: shared-key="coverage" (instrument-coverage artifacts are distinct) - bundle-check matrix: shared-key="bundle-check" (all 5 shards share one entry) - release build-binaries: shared-key="release-<target>" per target Secondary fix: move RUSTC_WRAPPER and SCCACHE_GHA_ENABLED from step-level env to job-level env so all cargo invocations in the job route through sccache, not just the explicit cargo step. release.yml: add sccache for native builds only; cross builds run inside a container where host sccache is not available.
1a7e79c to
37ea45d
Compare
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
shared-keyto allSwatinem/rust-cachesteps so jobs in the same workflow share one registry cache entry instead of creating independent keys per job. Without this, every job misses and re-downloads the full~/.cargo/registry.RUSTC_WRAPPER: sccache/SCCACHE_GHA_ENABLED: "true"from step-levelenvto job-levelenvso all cargo invocations in the job route through sccache, not just the explicit cargo step.release.ymlfor native builds; skip forcrossbuilds (run in a container where host sccache is unavailable).Cache layers (non-overlapping)
rust-cache(cache-targets=false)~/.cargo/registry,~/.cargo/gitshared-key + Cargo.lock hashsccache.rlibKey assignments
shared-keylint-clippy,build-testscicoveragecoverage(instrument-coverage artifacts differ from normal builds)bundle-check(5-shard matrix)bundle-checkreleasebuild-binariesrelease-<target>Expected outcome
After 2 consecutive warm runs on main: registry cache hit rate ~95%, sccache hit rate ~70-85% for incremental PRs (few files changed). Overall cache hit rate should rise from ~18% to 80%+.