Skip to content

perf(ci): split er-api's dependency layer out with cargo-chef - #423

Merged
athvin merged 1 commit into
mainfrom
bm/ci-dockerfile-chef
Nov 3, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/ci-dockerfile-chef

Conversation

@athvin

@athvin athvin commented Nov 3, 2026

Copy link
Copy Markdown
Owner

The measurement

rust/Dockerfile did COPY . . then one cargo build --release, so any change under rust/ recompiled all 408 crates including bundled DuckDB's C++. Measured twice today: 58m9s on the main build (run 41524220825) and 51m cold in the new verify job — paid on every rust-touching merge, with deploy-dev queued behind it.

The change

cargo-chef (pinned 0.1.78) splits the build in two: prepare reduces the workspace to a recipe (manifests + lockfile, no sources), cook builds the dependency graph against stubbed workspace crates, and sources arrive in a later layer. A source-only change then reuses the cooked dependency layer — which the ECR registry cache (#405/#407) carries between runs — and recompiles only the 33 workspace crates. The recipe changes when Cargo.toml/Cargo.lock does, which is exactly when the dependency build genuinely must re-run.

Two details that would have silently undone the whole thing:

  • .cargo/config.toml is copied before the cook. Its CXXFLAGS (the DuckDB release-version stamp) are part of libduckdb-sys's fingerprint — cooking without it builds DuckDB once in the cook and again after the sources arrive, i.e. the most expensive crate in the graph compiled twice for no gain.
  • --bin er-server is passed to cook as well as build. Cargo resolves features per selected target, so a whole-workspace cook would unify a different feature set and every crate whose features differed would recompile.

Why this is safe to land

Nothing in the workspace has a build.rs (checked) — that is the usual thing that breaks chef's stub phase. The restructure was validated locally through prepare (a 191KB recipe naming er-server and libduckdb-sys), and this PR is validated by the verify job added in #417 — the first Dockerfile change that gets a pre-merge build at all. Expect image builds (er-api, no push) to run cold here (~50m); the saving shows on the second build with a warm cache, which the first main build after merge will demonstrate.

🤖 Generated with Claude Code

@athvin
athvin force-pushed the bm/ci-dockerfile-chef branch from ff26b0d to a2a68af Compare November 3, 2026 02:16
athvin pushed a commit that referenced this pull request Nov 3, 2026
…entically

The prediction recorded in the previous commit resolved to structural, and
PRs are red again. #423's run, unchanged Cargo.toml, restored the v2 entry
and panicked the same way:

  Cache hit for: v2-rust-rust-Linux-x64-8556beb2-11e7c23f
  Restored from cache key "v2-rust-..." full match: true.
    unpacking bundled DuckDB sources: Os { code: 39, DirectoryNotEmpty }

`full match: true` is the point. The rust-cache KEY matched exactly; what
did not match is cargo's own fingerprint for the build script, which that
key does not model — two different notions of "valid cache", only one of
them checked. So a prefix bump buys exactly one cold green run per bump
(8578f99 was that run) and the next restore breaks again.

rust-cache therefore comes out of all seven sccache-backed compile jobs.
sccache is content-addressed per compilation unit and never touches
`target/`, so it cannot fail this way, and it was already doing the work:
two runs with `No cache found.` at a 99% hit rate finished in 8m03/8m45
while this entry held ~1.3 GB. Measured on this branch before the rebase:
8-13m per job, in line with the sharded baseline.

`coverage` keeps its entry — it opts out of sccache (llvm-cov owns
RUSTFLAGS), so there the trade really is 1.8 GiB against a timeout. This
also retires the single-writer rule: nothing in the Rust gate writes the
Actions cache now.

Co-Authored-By: Claude Fable 5 <[email protected]>
@athvin

athvin commented Nov 3, 2026

Copy link
Copy Markdown
Owner Author

The entities and lake-shard failures here are not this PR — they are the rust-cache poisoning returning. This run restored the new v2-rust entry full match: true and still panicked in libduckdb-sys with DirectoryNotEmpty, which settles the open question from #424: re-keying buys one cold run, not a fix. #424 now removes rust-cache outright; this PR should be re-run once that lands.

@athvin

athvin commented Nov 3, 2026

Copy link
Copy Markdown
Owner Author

Full local validation finished: exit 0, including the cook, the workspace build and the extension bake. It also measures the split precisely (arm64 laptop, so treat the absolute numbers as indicative and the ratio as the result):

stage time
cook — every dependency, bundled DuckDB included 4909s (81.8 min)
cargo build --release --bin er-server — the 33 workspace crates 195.6s (3.3 min)
COPY . . + strip + install-extensions ~15s

The workspace is 3.8% of the compile work. Everything else is the dependency graph that today's COPY . . invalidates and rebuilds on every rust-touching merge — the 58m9s (main) / 51m (cold verify) measured earlier. With the cook layer served from the ECR registry cache, a source-only merge pays only that 3.8% plus layer transfer.

The flip side, stated honestly: a merge that changes Cargo.toml or Cargo.lock re-cooks and is no cheaper than today. That is the right trade — dependency changes are rare, source changes are every merge.

athvin added a commit that referenced this pull request Nov 3, 2026
… red again (#424)

* docs(ci): record the rust-cache poisoning incident and what settles it

#422 fixed the red main by bumping prefix-key to v2. This writes down the
trail — including that the poisoning commit PASSES and the next unrelated
PR wears it, which is what made it look like those PRs' fault — and states
the one open question as an observation rather than an argument.

The mechanism needs only a restored populated out/ plus a fingerprint
mismatch, and this repo's jobs legitimately differ in fingerprint (lint is
the sole writer; test, the lake shards and the e2e slices each select
different packages and features). So either the mismatch only arises at a
dependency bump (v2 holds) or lint's tree can never satisfy the others
(v2 breaks on first restore). The discriminating observable is the next
main run with an unchanged Cargo.toml; the remedy if it is red is recorded
with it.

Co-Authored-By: Claude Fable 5 <[email protected]>

* fix(ci): remove rust-cache — v2 was restored full-match and failed identically

The prediction recorded in the previous commit resolved to structural, and
PRs are red again. #423's run, unchanged Cargo.toml, restored the v2 entry
and panicked the same way:

  Cache hit for: v2-rust-rust-Linux-x64-8556beb2-11e7c23f
  Restored from cache key "v2-rust-..." full match: true.
    unpacking bundled DuckDB sources: Os { code: 39, DirectoryNotEmpty }

`full match: true` is the point. The rust-cache KEY matched exactly; what
did not match is cargo's own fingerprint for the build script, which that
key does not model — two different notions of "valid cache", only one of
them checked. So a prefix bump buys exactly one cold green run per bump
(8578f99 was that run) and the next restore breaks again.

rust-cache therefore comes out of all seven sccache-backed compile jobs.
sccache is content-addressed per compilation unit and never touches
`target/`, so it cannot fail this way, and it was already doing the work:
two runs with `No cache found.` at a 99% hit rate finished in 8m03/8m45
while this entry held ~1.3 GB. Measured on this branch before the rebase:
8-13m per job, in line with the sharded baseline.

`coverage` keeps its entry — it opts out of sccache (llvm-cov owns
RUSTFLAGS), so there the trade really is 1.8 GiB against a timeout. This
also retires the single-writer rule: nothing in the Rust gate writes the
Actions cache now.

Co-Authored-By: Claude Fable 5 <[email protected]>

---------

Co-authored-by: bmoore813 <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
`COPY . .` then one `cargo build --release` meant ANY change under rust/ —
a one-line handler edit — invalidated the build layer and recompiled all
408 crates, bundled DuckDB's C++ included. Measured twice today: 58m9s on
the main build (run 41524220825) and 51m cold in the new PR verify job.
Every rust-touching merge paid it, with deploy-dev waiting behind.

cargo-chef splits it: `prepare` reduces the workspace to a recipe
(manifests + lockfile, no sources), `cook` builds the dependency graph
against stubbed workspace crates, and sources arrive in a later layer. A
source-only change now reuses the cooked dependencies — the ECR registry
cache carries that layer between runs — and recompiles only this
workspace's 33 crates. The recipe changes when Cargo.toml or Cargo.lock
does, which is exactly when the dependency build must genuinely re-run.

Two details that would have silently undone it: `.cargo/config.toml` is
copied BEFORE the cook, because its CXXFLAGS are part of libduckdb-sys's
fingerprint and cooking without it builds DuckDB twice; and `--bin
er-server` is passed to cook as well as build, because cargo resolves
features per selected target and a whole-workspace cook would unify a
different set.

No build.rs exists anywhere in the workspace, which is the usual thing
that breaks a chef stub phase. Validated locally through `prepare` (a
191KB recipe naming er-server and libduckdb-sys) and in CI by the verify
job this PR runs.

Co-Authored-By: Claude Fable 5 <[email protected]>
@athvin
athvin force-pushed the bm/ci-dockerfile-chef branch from a2a68af to d1b390d Compare November 3, 2026 02:33
@athvin
athvin merged commit c140dd1 into main Nov 3, 2026
40 checks passed
@athvin
athvin deleted the bm/ci-dockerfile-chef branch November 3, 2026 03:11
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.

2 participants