Skip to content

ci: keep sccache objects in one cache file for each job - #1766

Open
lukasIO wants to merge 2 commits into
mainfrom
claude/ci-sccache-local
Open

lukasIO wants to merge 2 commits into
mainfrom
claude/ci-sccache-local

Conversation

@lukasIO

@lukasIO lukasIO commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

sccache stores almost nothing in CI. In a Linux build job after #1760 and #1761, it failed to write 861 of 861 objects. The hit rate was 0% to 21% in the build jobs.

The cause: sccache with the GitHub backend uploads one cache entry for each compiled crate. A build job compiles about 860 units, and 14 jobs with sccache run at the same time. GitHub allows 200 cache uploads per minute for a repository and answers the rest with 429 Too Many Requests.

Change

sccache writes to a local folder. builds.yml and tests.yml no longer set SCCACHE_GHA_ENABLED. SCCACHE_DIR is a folder in the temp directory of the runner.

  • actions/cache/restore restores the folder before the build.
  • actions/cache/save saves it after the build, only on main and only if the exact key did not exist.
  • The key has the workflow, the target, and the hash of Cargo.lock and rust-toolchain.toml.
  • A PR restores the newest folder for its target and saves nothing.
  • A run on main restores only the exact key. After a change of Cargo.lock, it builds from zero and saves a folder without the objects of older locks.

Only 7 jobs keep a folder: the 3 test jobs and the 4 macOS and iOS build jobs. The folders of all 14 jobs are 9.0 GiB (see "Measured"), and a repository can keep 10 GB. The test jobs are the critical path of a run. The macOS jobs are the slowest build jobs. The other 7 build jobs use sccache only inside one run.

That is 7 uploads for each Cargo.lock on main, and none for a PR.

The probe step is gone. It started the sccache server to test the GitHub backend. A local folder has no such failure.

The registry caches follow the same rule. builds.yml, tests.yml and feature-combinations-curated.yml save the cargo registry only on main. Before, each Renovate PR saved its own copies, 4.4 GB in 66 entries.

A size report. Each job writes the size of its sccache folder to the job summary.

Measured

Run 46877828990 of this PR, before the limit to 7 jobs. sccache had 0 write errors and 0 read errors in all 14 jobs.

Job group Folder size for one job Sum
Test, 3 targets 778 to 932 MiB 2.5 GiB
Build macOS and iOS, 4 targets 660 to 723 MiB 2.7 GiB
Build Linux, 2 targets 539 and 543 MiB 1.1 GiB
Build Android, 3 targets 567 to 576 MiB 1.7 GiB
Build Windows, 2 targets 509 and 582 MiB 1.1 GiB

The 7 saved folders are 5.2 GiB.

Verified

  • actionlint passes on the three workflows.
  • The CI run of this PR passed with the local folder on each target.

Not done yet

  • The gain is not measured. A PR saves nothing, so the runs of this PR are cold. The gain shows only in PR runs after the first run on main.
  • The save and the restore are not tested. No run of this PR reaches the save step, because it runs only on main.
  • 7 build jobs get no gain: Linux, Android and Windows.
  • A partial folder is possible. The test job saves the folder also after a failed test, because that step fails often. A compile error on main then saves a folder with fewer objects, and the key stays until the next change of Cargo.lock.
  • Stale objects of the workspace crates. The folder holds the objects from one commit on main. The dependencies stay valid. The crates of this repository compile again in each PR.
  • The feature-combination jobs get no sccache.

🤖 Generated with Claude Code

sccache with the GitHub backend uploads one cache entry for each compiled
crate. GitHub allows 200 uploads per minute for a repository, so sccache
stored almost nothing. sccache now writes to a local folder that
actions/cache saves once for each job and Cargo.lock, only on main. The
registry caches follow the same rule.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@lukasIO
lukasIO requested a review from ladvoc as a code owner December 2, 2026 12:06
@lukasIO lukasIO added the internal to tag changes that don't require changelog documentation label Dec 2, 2026
@lukasIO lukasIO self-assigned this Dec 2, 2026

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: ${{ runner.temp }}/sccache
key: sccache-builds-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock', 'rust-toolchain.toml') }}

@devin-ai-integration devin-ai-integration Bot Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Unrelated lockfiles invalidate compiler caches

When a standalone workspace updates its lockfile, hashFiles changes every build and test compiler cache key. Neither the API generator nor the fuzz workspace participates in these jobs. The next main run recompiles unchanged dependencies and uploads replacement archives.

Learn more

The build and test jobs compile the root SDK workspace. The API generator and fuzz project each declare a separate workspace and keep their own lockfiles. hashFiles('**/Cargo.lock', 'rust-toolchain.toml') includes those lockfiles in both compiler archive keys, including the test restore key. Main does not use a fallback key, so changing either independent lockfile discards all existing compiler cache hits even when the SDK's inputs are identical.

Example: A dependency update changes the API generator's Cargo.lock but leaves the root lockfile and Rust toolchain untouched. After merge, main restores none of the compiler archives from the preceding run.

Recommended fix: Use hashFiles('Cargo.lock', 'rust-toolchain.toml') in both compiler cache keys so they track only the lockfile and toolchain those jobs consume.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

The folders of all 14 jobs are 9.0 GiB, measured in run 46877828990. A
repository can keep 10 GB.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal to tag changes that don't require changelog documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant