Skip to content

CI: main's build cache fits every runner, and release-paths and macOS use it too - #2252

Merged
ashhart merged 3 commits into
mainfrom
lead/ci-cache-compile-jobs
Nov 5, 2026
Merged

ashhart merged 3 commits into
mainfrom
lead/ci-cache-compile-jobs

Conversation

@ashhart

@ashhart ashhart commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

A kept build cache only helps if it fits the runner that restores it, and on GitHub's x86 runners it mostly didn't. This makes main's cache fit every runner, and moves release-paths and zig-macos-dev-tools onto the same cache.

Why a restored cache missed

A compile's cache key carries its CPU, and host code compiles for the runner's own CPU. GitHub's runners differ: in these runs Linux drew EPYC 9V45, 9V74 and 7763 and Xeon 8370C and 8573C, and Windows drew Xeon 8370C and EPYC 7763, 9V45 and 9V74. So a restored cache hit only when a runner drew the CPU main's last save ran on.

In a probe on a small target (run 42027275042), 1 of 4 restored Linux jobs hit and 0 of 4 on Windows. With -Dfixed-cpu, which compiles host code for x86_64_v3, all 8 hit, in 2-7 s instead of 108-263 s.

The suite passes on x86_64_v3 at full size (run 42038532226): Linux 7,127 passed and 59 skipped in 701 s cold, Windows 6,576 passed and 141 skipped in 1,475 s cold. A Windows job that restored that cache on a different CPU took 329 s, with every test run again. That is one run of each, and the restoring CPU was newer, so it isn't an exact ratio.

What changes

  • -Dfixed-cpu on every zig build line in zig, zig-windows and release-paths. It only sets the host CPU on x86_64, and only when asked, so local builds keep their native CPU. zig-macos-dev-tools runs on arm64 and doesn't need it.
  • release-paths and zig-macos-dev-tools restore main's newest cache and save nothing on a pull request, as zig and zig-windows do. Each pull request run saved about 1 GB of its own cache (about 520 MB for macOS, 475 MB for release-paths) that no other pull request could read. On 5 Nov the repository held 11.9 GB against GitHub's 10 GB limit, and a 936 MB entry was evicted within about an hour.
  • Cache keys move to v3, so main starts from an empty cache rather than keeping builds for each CPU alongside the new one.
  • The ZIG_GLOBAL_CACHE_DIR lines CI: zig and zig-windows keep main's build cache, and the quick checks run first #2140 added are gone. They did nothing, and the reason CI: zig and zig-windows keep main's build cache, and the quick checks run first #2140's commit message and this PR's first version gave for the misses was wrong: setup-zig already puts the global cache inside .zig-cache and overrides that setting from its step on.

What it doesn't do

  • Tests still run again on every pull request. -Drerun-tests stays until the next PR, which lets a pull request reuse main's passes.
  • C and C++ sources still recompile on a fresh checkout. Zig's cache check misses on any stat change to a declared input, and a checkout gives every file a new one. On Windows that is 13 test compiles and 8 libraries, about 2.4 minutes summed. The next PR deals with this too.
  • A change to zig/src/core, platform, hip or zig/src's top-level files still recompiles nearly everything.
  • release-paths and macOS have no warm number in this form yet, so they claim the budget saving and no particular speedup.

Test plan

  • This PR's CI passes, and its jobs log a clean miss, since main hasn't saved a v3 key yet
  • After landing: main saves each key, and the next pull request restores it on a different CPU and its compile steps show cached

@ashhart
ashhart force-pushed the lead/ci-cache-compile-jobs branch from 0dca2c7 to 8cc4afd Compare November 5, 2026 17:40
@ashhart ashhart changed the title CI: release-paths and the macOS dev tools use main's build cache too CI: main's build cache fits every runner, and release-paths and macOS use it too Nov 5, 2026
…ts every runner

A compile's cache key carries its CPU, and host code compiles for the runner's own.
GitHub's runners differ, so a restored cache missed nearly every compile unless the
runner drew the CPU main's last save ran on. In one probe on a small target, with
four different CPUs among the Linux runners, 1 of 4 restored jobs hit on Linux and 0
of 4 on Windows. With -Dfixed-cpu, which compiles host code for x86_64_v3, all 8 hit,
in 2-7 s instead of 108-263 s.

This removes the ZIG_GLOBAL_CACHE_DIR setting #2140 added. It does nothing on CI:
setup-zig already puts the global cache inside .zig-cache and overrides it, so the
reason that commit gave for the misses was wrong.

The key moves to v3, so main starts from an empty cache rather than keeping builds for
each runner's own CPU alongside the new one.
These two jobs only compile, so a warm cache saves most of their time. Pull requests
saved their own caches, which no other pull request can read and which filled the
budget, and setup-zig emptied any past 2 GiB. macOS waited longest for a runner: 10
minutes at the median and 39 at p90, then 13 to run (5 Nov, 63 pull request runs).

They now do as zig and zig-windows do: main saves, and a pull request restores main's
newest and saves nothing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant