Skip to content

fix(ci): improve cache hit rate with shared-key and job-level sccache env#2324

Merged
bug-ops merged 1 commit intomainfrom
fix/ci-cache-hit-rate
Mar 28, 2026
Merged

fix(ci): improve cache hit rate with shared-key and job-level sccache env#2324
bug-ops merged 1 commit intomainfrom
fix/ci-cache-hit-rate

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Mar 28, 2026

Summary

  • Add shared-key to all Swatinem/rust-cache steps 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.
  • Move RUSTC_WRAPPER: sccache / SCCACHE_GHA_ENABLED: "true" from step-level env to job-level env so all cargo invocations in the job route through sccache, not just the explicit cargo step.
  • Add sccache to release.yml for native builds; skip for cross builds (run in a container where host sccache is unavailable).

Cache layers (non-overlapping)

Layer Tool Caches Key
Registry downloads rust-cache (cache-targets=false) ~/.cargo/registry, ~/.cargo/git shared-key + Cargo.lock hash
Compiled artifacts sccache object files, .rlib content hash of source

Key assignments

Jobs shared-key
lint-clippy, build-tests ci
coverage coverage (instrument-coverage artifacts differ from normal builds)
bundle-check (5-shard matrix) bundle-check
release build-binaries release-<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%+.

@github-actions github-actions bot added bug Something isn't working ci CI/CD configuration size/S Small PR (11-50 lines) and removed bug Something isn't working labels Mar 28, 2026
@bug-ops bug-ops enabled auto-merge (squash) March 28, 2026 08:11
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.
@bug-ops bug-ops force-pushed the fix/ci-cache-hit-rate branch from 1a7e79c to 37ea45d Compare March 28, 2026 08:16
@github-actions github-actions bot added the bug Something isn't working label Mar 28, 2026
@bug-ops bug-ops merged commit 9e661aa into main Mar 28, 2026
25 checks passed
@bug-ops bug-ops deleted the fix/ci-cache-hit-rate branch March 28, 2026 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ci CI/CD configuration size/S Small PR (11-50 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant