Skip to content

CI builds are incremental: file times pinned to content, old .build caches pruned - #301

Merged
Mpdreamz merged 1 commit into
mainfrom
ci/incremental-builds
Nov 19, 2026
Merged

Mpdreamz merged 1 commit into
mainfrom
ci/incremental-builds

Conversation

@Mpdreamz

Copy link
Copy Markdown
Contributor

Follows #300. Even with a restored .build, every CI run recompiled heed's own sources in full.

Cause

Swift Build rebuilds an input whose modification time changed. The inode does not matter and neither does the direction: a copy with the same content and mtime but a new inode rebuilt in 10 s (a no-op), while the same content with a fresh mtime rebuilt for 516 s, and a changed file with an older mtime rebuilt too. A fresh git checkout stamps every file with the time it ran, so main's cache never matched.

Changes

  • scripts/pin-mtimes.sh stamps each tracked file with a time derived from its git blob id: same content, same time, on every checkout (a collision is 1 in 2^28). No history is needed, so the clone stays shallow (the repository is 1.5 GB, so a full fetch would cost more than it saves). The setup action runs it first, so the release workflow gets it too.
  • The test job no longer touches its sources to force every warning. text-check reads what the incremental build compiled: a file that did not recompile was clean when main compiled it, and a file that depends on a changed declaration (the deprecations in Prompt.swift) recompiles.
  • scripts/prune-caches.sh keeps each job's newest two .build caches after main saves one. The repository's cache allowance was full (10.38 of 10 GB, 15 caches, each run adding ~700 MB), so GitHub was evicting by least recent use. A read-only dry run of the selection keeps the newest two per job, would free about 5.8 GB, and matches no GhosttyKit, toolchain or mise cache. Both jobs get actions: write for it; it only runs on main.

Verified

  • Locally, on the test product at the same path CI uses: after a simulated fresh checkout (every file copied to a new inode, new mtime, same content) plus the pin, the rebuild took 10 s instead of 516 s; one changed file (ExternalText.swift, used widely) took 20 s.
  • Not verified until it runs on CI: that the saved cache is reused on a runner. This PR's own CI is still a full build, because main's cache was saved with checkout-time mtimes. The gain shows on the next main run and on the pull request after it; I will measure that and report it.
  • Not covered: the release build is whole-module, so a change to HeedCore still recompiles it and the app in full.

🤖 Generated with Claude Code

A restored .build was no help to heed's own sources. Swift Build rebuilds an input whose modification time changed (a
copy with the same content and mtime but a new inode is a no-op), and a fresh checkout gives every file a new mtime,
so each run recompiled HeedCore, the tests and the app in full whatever main had cached.

- scripts/pin-mtimes.sh stamps every tracked file with a time derived from its git blob id, so the same content has
  the same time on every checkout. The setup action runs it first. No history is needed, so the clone stays shallow.
- The test job no longer touches its sources to force every warning: text-check reads what the incremental build
  compiled. A file that did not recompile was clean when main compiled it, and a file that depends on a changed
  declaration recompiles.
- Main kept every .build cache it ever saved (about 700 MB each) until the 10 GB allowance was full and GitHub evicted
  whatever was least recently used. scripts/prune-caches.sh keeps each job's newest two after the save.

Measured locally on the test product: after a simulated fresh checkout (new inodes and mtimes, same content) a rebuild
took 10 s instead of 516 s, and one changed file took 20 s. The first run after this merges is still a full build,
because main's cache was saved with checkout-time mtimes.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@github-actions github-actions Bot added the chore Maintenance label Nov 19, 2026
@Mpdreamz
Mpdreamz merged commit cd07305 into main Nov 19, 2026
5 checks passed
@Mpdreamz
Mpdreamz deleted the ci/incremental-builds branch November 19, 2026 16:20
Mpdreamz added a commit that referenced this pull request Nov 19, 2026
…an be listed (#302)

The local half of the build-speed work (#300 and #301 are CI's). With
several agents building at once, each `swift build` starts a compiler
per core. The machine here (8 cores, 16 GB) sat at a load of 20 to 60
with 5 of 6 GB of swap used while four or five agents compiled.

## Changes
- `scripts/slot.sh CMD...` runs a command in one of two slots shared by
every worktree. A slot is a directory holding its owner's pid (no
`flock` on macOS's bash 3.2). A waiter prints who is building; a killed
owner's slot is taken over, including one that died before writing its
pid. `HEED_BUILD_SLOTS=N` sets the count and `0` turns it off. `mise run
test | check | build | bundle | bench | live`, `text-check` and
`ghostty` go through it. The test run itself (about 25 s) does not take
a slot.
- `scripts/prune-worktree-builds.sh [DAYS]` lists worktrees whose
`.build` is idle with sizes, skipping the main checkout and any worktree
building right now. It deletes only with `--delete`.

## Findings that shaped it
- Seeding a new worktree with a copy-on-write clone of another's
`.build` does not work: the clone took 587 s and 77 build steps at a
different path, a full rebuild. Swift Build ties its state to the
absolute path, so there is nothing to share between worktrees and the
only lever is not keeping idle ones.
- This machine: 35 worktrees are idle 3 days or more and hold 90 GB of
`.build` (listed, not deleted).

## Verified
- `slot.sh`, with `HEED_SLOT_DIR` pointed at a scratch directory: with
two slots a third job waited for one to free (6 s) and said so; the
command's exit status passes through (7); after `kill -9` on both
holders a new job took a slot at once; `HEED_BUILD_SLOTS=0` runs
directly. `mise run test` goes through a slot (no-op build plus the
filtered tests, 19 s).
- Not verified: the count of 2 is a judgement for this machine, and I
have not measured total throughput with several agents queued. The
pid-less dead-owner path (freed after a minute) was written but not
exercised.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
Mpdreamz added a commit that referenced this pull request Nov 19, 2026
…only (#304)

Agreed with the owner in chat. The release build is whole-module, so
pinned file times (#301) cannot make it incremental. It took 14 to 26
minutes on every pull request, longer than the rest of ci together.

## Changes
- `build` (a required check, so it still runs on pull requests) compiles
the app in **debug**, which is incremental on the cache main saves. It
bundles with `scripts/bundle.sh debug`, then runs the appcast and tutor
checks on that bundle. `text-check` reads its log, which covers
HeedCore, the helper and the app.
- `release-build` is new and runs on pushes to main only: the same `mise
run bundle`, saving its `.build` under its own cache name and pruning
old ones.
- `release.yml` restores that cache (`cache: release`), so a release
still starts from main's release build. It builds the release again
before it publishes, so a release-only break cannot ship; it now shows
on the merge instead of on the pull request.

## Not verified
- The tutor check on a **debug** bundle has not been run anywhere yet
(it launches the app, so I did not run it on the owner's machine). This
PR's own CI is the first run; if it fails there, the fix is to keep the
tutor on the release build.
- The first run is a full debug build including MLX, because no debug
cache exists yet. The gain shows from the second main run on.
- `release-build` is not in the branch protection list (`build`, `docs`,
`test`) and a failure there does not block anything.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant