Skip to content

CI: zig and zig-windows keep main's build cache, and the quick checks run first - #2140

Merged
ashhart merged 2 commits into
mainfrom
lead/ci-build-cache
Nov 5, 2026
Merged

ashhart merged 2 commits into
mainfrom
lead/ci-build-cache

Conversation

@ashhart

@ashhart ashhart commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

zig and zig-windows rebuild from scratch on every run. mlugg/setup-zig empties its cache folder past 2 GiB and saves the empty folder, and both jobs have outgrown that. From main's green run: Cache directory reached 5931725721 bytes, exceeding limit of 2147483648 bytes; clearing cache.

  • Main saves, pull requests only restore. Main saves the cache after each run, and pull requests add nothing to the 10 GB budget. A pull request's run tests its merge with the latest main, so with main's newest cache it compiles little beyond its own diff.
  • One build in the cache. The key carries a hash of zig/src/core, zig/src/platform, zig/src/hip and zig/src's top-level files. Nearly every test imports them (96%, 87%, 76% and 88% of 126 test builds sampled from our gate cache), so a change there recompiles nearly everything, and main then starts from nothing. Adding to the old cache instead took it from about 0.85 to 1.5 GB on one core edit, which would have filled the budget within a day or two.
  • Every check still runs. -Drerun-tests reruns all checks, whatever the cache holds, and only compiles are reused. A test that reads a fixture at run time can't pass on an old result. Generators keep their cache.
  • Quick checks first. The shared CUDA copies check and the lean check take about three seconds, so a failure there shows in seconds rather than after 18 minutes. A probe run failed this way in under a minute.

The other jobs keep setup-zig's own cache; this PR doesn't touch them.

Measurements

Job time in minutes:

zig zig-windows
Main today, cold, 17 runs on 4 Nov 12.0-19.2 15.8-31.3
Same, median 16.4 26.3

The warm numbers I gave here earlier were wrong, so I've removed them, and the cause I gave for that was wrong too. I said the runs had missed zig's global cache, and added ZIG_GLOBAL_CACHE_DIR to fix it. That setting does nothing on CI: setup-zig already puts the global cache inside .zig-cache and overrides it. It will be removed. The misses themselves are real: on one fresh runner, 224 of 240 compiles and all 235 test runs repeated. A different cause is being tested on #2172 and tracked on #2242. This PR claims no speedup until that's settled.

Where the test time goes is now measured in #2172. zig/qwen4_family.zig alone takes over 6 minutes on Linux and over 3 on Windows. That's the next thing to fix.

Also seen while testing, and not from this PR: two zig-windows runs on 4 Nov hit the 60-minute limit with no output after 28 minutes, while others on the same base passed. That hang is still unexplained.

Test plan

  • Cold, warm-after-edit and warm-unchanged runs pass on both jobs, on the earlier form
  • -Drerun-tests reruns a test the cache would have skipped (run test cached without it, a real run with it)
  • build_options_test passes with the new option
  • This head's own CI passes with the new keys
  • A fresh runner restoring this cache reuses its compiles, on Linux and Windows (probe, do not land: what a test run reuses on a fresh runner #2172)
  • After landing: main's first save, main's next run restoring it when the hash is unchanged and starting empty when it changed, and a real PR restoring it

… run first

setup-zig empties its cache past 2 GiB and saves the empty folder. Both jobs have
outgrown that (Linux 5.9 GB, Windows 3.7 GB), so every run restores nothing and
rebuilds from scratch: zig p50 17.8 minutes, zig-windows 24.2.

Main now saves the cache after each run, and pull requests restore main's newest and
save nothing. A pull request's run tests its merge with the latest main, so it compiles
little beyond its own diff.

Nearly every test imports core, platform, hip and zig/src's top-level files, so a change
to them recompiles nearly everything. The key carries their hash, and main starts from
nothing when it changes. That keeps one build in the cache: adding to the last one
doubled it (0.85 to 1.5 GB on one core edit).

A compile's manifest names builtin.zig files in zig's global cache, and a fresh runner
has none, so restoring .zig-cache alone missed nearly every compile. The global cache now
sits inside .zig-cache and is kept with it.

The cache saves compiles only. -Drerun-tests makes every check run again, as it
does today, so a test that reads a fixture at run time can't pass on an old result.
Generators keep their cache, since compiles read what they write.

The shared CUDA copies check and the lean check take about three seconds and were
three of the last four red mains. They now run before the builds.
@ashhart
ashhart force-pushed the lead/ci-build-cache branch from dfd8699 to 84e44eb Compare November 5, 2026 11:10
@ashhart
ashhart merged commit 5f110ed into main Nov 5, 2026
7 checks passed
ashhart added a commit that referenced this pull request 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.
ashhart added a commit that referenced this pull request 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.
ashhart added a commit that referenced this pull request 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.
ashhart added a commit that referenced this pull request 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.
@ashhart
ashhart deleted the lead/ci-build-cache branch November 10, 2026 16:34
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