Skip to content

ci: speed up coverage build with mold linker + debug-info trim - #484

Merged
thiras merged 5 commits into
mainfrom
ci/mold-coverage-debug-trim
May 8, 2026
Merged

thiras merged 5 commits into
mainfrom
ci/mold-coverage-debug-trim

Conversation

@thiras

@thiras thiras commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The merged test+coverage job (#476) is the sole wall-clock driver on PR CI: ~3m21s of a ~4m run, with the Run tests step alone at 2m20s. Every other job finishes in under a minute and parallelizes off the critical path. This PR attacks the build/link phase of that step with three knobs:

  • mold linker via -C link-arg=-fuse-ld=mold — installed via apt at job start, routed through RUSTFLAGS. Faster final link of the workspace's instrumented test binaries.
  • -C debuginfo=line-tables-only — emits only the .debug_line DWARF section, which is what cargo-llvm-cov reads to map counters to source lines for SF/DA records in lcov.info. Strips subprogram DIEs and all type/variable info.
  • -C split-debuginfo=unpacked — side-file debug info, smaller .o files, faster relinking, smaller cached target/.

Plus CARGO_INCREMENTAL=0 (incremental files bloat the cache for no gain on a single CI run) and --no-clean on cargo llvm-cov nextest (suppresses cargo-llvm-cov's per-package cargo clean that would otherwise wipe the rust-cache restore).

Env scope (job-level, not step-level)

RUSTFLAGS and CARGO_INCREMENTAL live at the test job's env: block. This is load-bearing: Swatinem/rust-cache reads process.env at the moment its own step runs, and hashes CARGO_*/RUST_* env vars into its cache key. With job-level scope, rust-cache sees the new RUSTFLAGS, gives the coverage partition a key that uniquely reflects the build configuration, and the post-job step actually saves the freshly-built target.

An earlier draft of this PR scoped the env at the step level — which made rust-cache invisible to it. The result was the wrong-cache-restore-then-skip-save trap: rust-cache restored main's old-flag target, cargo's per-artifact fingerprint detected the new RUSTFLAGS at compile time and rebuilt everything from scratch (~6m), then the post-step skipped the save with "Cache up-to-date" because the unchanged key already existed. The freshly-built target was thrown away every run. See commit 6a00c37 for the fix.

The job-level scope is bounded — other jobs (clippy, doc, msrv) are in their own job blocks and don't inherit this env, so their warm caches are preserved.

What is not changing

  • Coverage stays a blocking PR signal — no changes to ci-success needs: or allowed-skips.
  • coverage-diff.py and the sticky-comment plumbing are untouched.
  • No Rust source changes; no Cargo.toml changes; other jobs (clippy, doc, msrv, deny) are untouched.
  • release.yml still uses sccache for native binary builds (separate path, separate cache).

Measured impact (warm-cache run 25566849732 on commit 45bfabc)

Metric Baseline (run 25562733813) This PR (warm cache) Δ
Run tests step 139s 85s −54s (−39%)
Cache restore 35s 20s −15s (smaller target/)
Install mold (n/a) 14s +14s (new step)
test job total 201s (3m21s) 156s (2m36s) −45s (−22%)
End-to-end PR wall-clock ~4m ~2m45s ~−1m15s

Other jobs (clippy 54s, doc 75s, msrv 41s, deny 55s) are within CI runtime variance of their baselines — env scoping kept their caches isolated.

Cold-cache penalty (one-time, on merge to main): coverage shared-key invalidates because the cache key changed; the merge run will rebuild from scratch (~7m30s for the test job) and save the new cache. Every subsequent PR hits warm.

Sub-2m wall-clock would require a paid larger GitHub-hosted runner (e.g. ubuntu-latest-4-core, ~2× minute multiplier for ~2× cores). Deferred — current numbers meet the goal.

Test plan

  • First CI run on this PR completes successfully.
  • Cache key uniquely reflects the new RUSTFLAGS (v0-rust-coverage-Linux-x64-d64fc7f4-b23bd388, hash differs from baseline …ae62368c…).
  • Post-step actually saves the cache after a cold run (run 25566274171: "Saving cache…", 751MB upload).
  • Warm-cache run hits cleanly and beats baseline (run 25566849732: Run tests 85s vs 139s baseline; test job 156s vs 201s baseline).
  • Coverage sticky comment posts as before with non-empty per-file rows (debuginfo=line-tables-only retained line tables).
  • lcov.info artifact format unchanged: coverage diff comment shows 87.90% consistent with baseline.
  • clippy, doc, msrv job durations remain near baseline — env scoping kept their caches warm.

🤖 Generated with Claude Code

The merged test+coverage job (PR #476) is the sole driver of PR
wall-clock — ~3m21s out of ~4m end-to-end on a recent successful run
(25562733813), with the `Run tests` step alone consuming 2m20s of
that. Other jobs all parallelize within ~50s.

Three step-scoped changes attack the build/link phase:

* Install `mold` and route the final link through it via
  `-C link-arg=-fuse-ld=mold`. Workspace links ~8 instrumented test
  binaries (alloy/iroh/tokio/aws-sdk dep tree); mold is typically
  5–10× faster at the link step than ld.
* `-C debuginfo=1` (line-tables-only). cargo-llvm-cov only needs the
  `.debug_line` section to map counters to source lines for the
  SF/DA records in lcov.info; full DWARF type/variable info is
  unnecessary. Documented as the recommended setting in cargo-llvm-cov.
* `-C split-debuginfo=unpacked` puts debug info in side files
  instead of inline in object files; smaller .o files mean faster
  linking and a smaller cached target tree.

Plus `CARGO_INCREMENTAL=0` (incremental files bloat the cache for no
gain on a single CI run) and `--no-clean` on `cargo llvm-cov nextest`
(explicit "trust the cached target", matches modern default).

All knobs are scoped to the `Run tests` step's env block on purpose:
Swatinem/rust-cache hashes env into its key, so this only invalidates
`shared-key: coverage` on the merge run. The clippy/doc/msrv shared
keys stay warm — keeping the steady-state PR wall-clock as the goal,
not the one-time merge cost.

Coverage is preserved as a blocking PR signal; no changes to
ci-success `needs:` or `allowed-skips`. The post-processing
(LCOV diff, sticky comment) is unaffected.

Expected: `Run tests` 2m20s → ~1m45s–2m, full PR wall-clock
~4m → ~3m–3m15s. Sub-2m would need a paid larger runner, deferred.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 8, 2026 15:38
@gemini-code-assist

Copy link
Copy Markdown

Note

Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to reduce the wall-clock time of the CI test job (which runs cargo llvm-cov nextest) by speeding up linking and trimming debug info, while keeping the optimizations scoped to the coverage step to avoid invalidating other Swatinem/rust-cache partitions.

Changes:

  • Install mold in the test job to accelerate linking.
  • Scope RUSTFLAGS to the coverage test step to enable mold, use debuginfo=1, and enable split-debuginfo=unpacked.
  • Disable incremental compilation for that step and add --no-clean to cargo llvm-cov nextest.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/ci.yml Resolved
@github-actions

github-actions Bot commented May 8, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 87.90% (was 87.89%, ▲ +0.01%) — 11851/13483 lines

No Rust files changed in this PR.

History
Commit Total Δ vs base
9fea710 87.90% ● 0.00%
3472b38 87.90% ● 0.00%
6baaef7 87.89% ▼ 0.01%
6a00c37 87.90% ▲ +0.01%
45bfabc (HEAD) 87.90% ▲ +0.01%

thiras and others added 4 commits May 8, 2026 18:49
Per review feedback on PR #484: clippy/doc/msrv jobs do still link
build scripts and proc-macro cdylibs, even though they don't link the
final test binaries. Reword the comment to reflect what the scoping
decision is actually about — mold's wall-clock impact is dominated
by the test job's many large instrumented binaries — instead of
overstating that other jobs don't link at all.

No behavior change.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Self-review caught real issues that flowed from the original commit's
comments into the actual flag choice. Fixing:

* RUSTFLAGS bug: was `-C debuginfo=1`, now `-C debuginfo=line-tables-only`.
  Per `rustc -C help`, `=1` is the alias for "limited", which still
  emits subprogram DIEs and inlined-call info. `=line-tables-only` is
  strictly tighter — exactly the `.debug_line`-only output the comment
  block claimed we were already producing. Behavior change: build now
  actually emits less debug info than before.

* Swatinem/rust-cache mechanism comment was wrong. The original wording
  said setting RUSTFLAGS at step level "invalidates the coverage shared-
  key." That's not what happens: the rust-cache step runs earlier in
  the job and doesn't observe this step-level env, so the cache key
  isn't invalidated at all. The actual mechanism is cargo's per-artifact
  fingerprint detecting the RUSTFLAGS change and recompiling affected
  crates within the restored target/. Conclusion (clippy/doc/msrv stay
  warm) still holds, but for a different reason.

* `--no-clean` comment was inverted. cargo-llvm-cov runs
  `cargo clean --package <each>` per invocation by default; --no-clean
  actively suppresses that. Without it, the rust-cache restore would
  be wiped by cargo-llvm-cov before the build started. The flag is
  doing real work, not just being defensive.

Also dropped rot-prone counts from the comments (8-crate, ~8 binaries,
specific dep names). The reasoning stands without them and they go
stale every time a crate is added.

No semantic change to the linker (still mold), the split-debuginfo
setting, the cache-disable knob, or the --no-clean flag itself. Only
the debuginfo level changes: limited → line-tables-only.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Step-level env was the wrong scope. Evidence from PR #484's first three
runs (all ~7m50s for the test job, vs ~2m20s baseline):

  Run 1 (cold): "Cache hit for: v0-rust-coverage-...-ae62368c-b23bd388"
                — restored main's old-RUSTFLAGS target.
  Build:        starts compiling proc-macro2/quote/syn/serde from scratch
                — cargo's per-artifact fingerprint saw the new RUSTFLAGS
                in step env and invalidated everything in the restored
                target/.
  Post:         "Cache up-to-date." — Swatinem skipped the save because
                its cache key (computed without seeing the step env)
                matched an existing entry.
  Run 2 & 3:    same key, same restore, same full rebuild, same skipped
                save. Groundhog Day.

Fix: hoist RUSTFLAGS and CARGO_INCREMENTAL from the `Run tests` step's
env to the job's env. rust-cache's `Swatinem/rust-cache` step then runs
inside this env, hashes RUST*/CARGO* env into its cache key (per its
config.ts), and gives the `coverage` partition a key that actually
reflects the build configuration. First post-merge run misses cleanly
once and saves the new target; every subsequent run hits warm.

The env is bounded to this job's `env:` block, so other jobs
(clippy/doc/msrv) still don't inherit it. Their warm caches are
preserved — that property was already verified on the prior runs
(clippy ~45s, doc ~45s, MSRV ~43s, unchanged from baseline).

Comment block at the previous step-level `env:` location moves to the
job-level `env:` and is rewritten to reflect the actual mechanism. The
narrative comment at the `Run tests` step is shortened — it no longer
needs to re-explain RUSTFLAGS scoping, only the `--no-clean` rationale.

No semantic change to mold, debuginfo level, split-debuginfo, or
CARGO_INCREMENTAL=0; only the env's *scope* changes.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
No-op commit to force a CI run that hits the freshly-saved
v0-rust-coverage-Linux-x64-d64fc7f4-b23bd388 cache cleanly. The
preceding run (6a00c37) was a one-time cache miss after the cache-key
fix landed; this run is the actual wall-clock measurement.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@thiras
thiras merged commit 83d725e into main May 8, 2026
11 checks passed
@thiras
thiras deleted the ci/mold-coverage-debug-trim branch May 8, 2026 16:45
thiras added a commit that referenced this pull request Jul 23, 2026
…d/debuginfo tuning (#1417)

The single anvil-e2e job was compile-dominated (~17m cold: settlement ~6m,
build daemon+CLI ~4m, journeys ~5m). The three decdn-node compiles are
genuinely distinct build contexts cargo can't share, so the redundancy can't
be dissolved in-place. Two orthogonal wins instead:

- Split into `anvil-e2e-settlement` (in-process settlement e2e, no bin build)
  and `anvil-e2e-journeys` (bins + cross-layer journeys), running concurrently
  so the two independent compiles overlap. Distinct rust-cache shared-keys;
  ci-success gate updated in both `needs` and `allowed-skips`.
- Apply the `test` job's proven tuning to both: mold linker +
  `debuginfo=line-tables-only` + `split-debuginfo=unpacked` + `CARGO_INCREMENTAL=0`
  at job level (so rust-cache keys it, per the PR #484 pattern). The job links
  ~16 binaries with the system linker and full debuginfo today.

Settlement bound sized at 60m for the cold-cache first run (new key, nothing to
restore); journeys keeps 130m. Corrected the relocated journeys timeout
inventory to the actual 16 tests / 13 files (summing to 218m, ~109m balanced):
dropped the phantom G-ORIGIN-04, added the G-GOV-02 and G-NODE-08 journeys.

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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