Skip to content

bench: frozen Bevy link corpus — compile once per platform, replay the link every iteration #55

Closed

Description

@zackees

Summary

Add a frozen Bevy link corpus to the benchmark harness: compile Bevy once per platform, freeze the resulting linker inputs (object files + .rlibs + native libs) and the captured final link command, then replay only the link on every benchmark iteration. This removes compilation from the measurement loop — each iteration times objects → linker → executable, nothing else — and gives a large, realistic Rust workload (link.exe vs lld-link vs rust-lld vs mold vs reld) without waiting on cargo build each run.

Bevy is a good corpus: big dependency graph, lots of crates/codegen units, heavy debug info — a painful, representative Rust dev link.

Motivation

Today reld-bench (in reld-testkit) drives synthetic scenarios. A frozen Bevy corpus gives a real-world heavy link that is:

  • Stable — same inputs every run, so linker-vs-linker deltas aren't polluted by recompilation variance.
  • Fast to iterate — no compile per iteration; only the link is replayed (50–100×).
  • Representative — matches the "200th rebuild of the day" dev-loop link reld exists to optimize.

How to build the corpus (compiler settings)

Build Bevy once with a profile tuned to produce a realistic, link-heavy workload — not an optimized/LTO build (we want to time linking, not whole-program optimization):

[profile.linkbench]
inherits = "dev"
opt-level = 0            # dev-style codegen, don't spend time optimizing
debug = 2               # full debug info -> much heavier, representative link
incremental = false     # frozen inputs; no incremental artifacts changing the experiment
lto = false            # time object-files -> linker, NOT bitcode -> WPO -> codegen -> link
codegen-units = 256    # high fragmentation -> more independent objects -> more linker work
# split-debuginfo = "off"  # (where applicable) keep debuginfo in the objects

Then capture the actual final link invocation (not a hand-rolled --emit=obj, because the real link feeds main-crate objects + .rlibs + native/system libs + build-script flags):

cargo build --profile linkbench                 # build once
cargo rustc --profile linkbench -- --print link-args   # capture the exact linker command

rustc --print link-args emits the full linker executable + argument list. Freeze all referenced inputs (the main.*.o objects, lib*-*.rlib archives, and native libs) and the command, then replay it per iteration with the linker binary swapped:

hyperfine --prepare 'rm -f bevy_app' './link-command.sh'   # per linker: link.exe / lld-link / rust-lld / mold / reld

Notes:

  • mold consumes .rlib fine — an .rlib is an archive of native objects (+ Rust metadata the linker ignores); by final-link time rustc has already selected the participating .rlibs. Cleanest on Linux/ELF.
  • Windows/MSVC .rlib/link.exe handling is a different ecosystem — scope the mold leg to Linux; use link.exe/lld-link on MSVC.
  • Freeze per platform (x86_64-linux, x86_64-pc-windows-msvc, aarch64-apple-darwin), since objects and the link command are platform-specific.

Proposal

  1. A prep step that builds Bevy (pinned version) once per platform with the linkbench profile and captures --print link-args.
  2. Freeze the linker inputs + normalized link command as a versioned corpus (checked-in manifest + cached/published blobs, keyed on the pinned Bevy version + platform — a natural fit for the setup-soldr side-cache in feat: cache arbitrary extra folders via glob-filtered, zstd side cache (auto-inflate) setup-soldr#463).
  3. reld-bench gains a "replay a frozen link N times, swapping the linker" mode that runs the corpus and reports per-linker medians alongside the existing scenarios.
  4. Corpus refresh is explicit (bump the pinned Bevy version), not silent.

Open questions

  • Pin a specific Bevy version (frozen) — which release? Pin it and its Cargo.lock so the corpus is reproducible.
  • Where to store the frozen blobs — Git LFS, a release asset, or a cache channel (ties into setup-soldr#463 / soldr toolchain publishing)? Objects + rlibs for a Bevy build are large.
  • Link-command normalization across machines — the captured command has absolute paths and hashed filenames; needs rewriting to the frozen corpus dir at replay time.
  • Cross-platform capture — --print link-args must be captured on each target's native runner (or via the soldr cross toolchain once feat: 'soldr cc --target x86_64-linux-gnu.2.17' zig-style cross compiler + published soldr-toolchain (build tools ourselves, no CC hacks) soldr#2335 lands).

Acceptance criteria

  • Bevy (pinned version) is built once per platform with a documented link-heavy, non-LTO profile; the final link command is captured via rustc --print link-args.
  • The linker inputs + command are frozen into a versioned, reproducible corpus (keyed on Bevy version + platform).
  • reld-bench can replay the frozen link N times per linker (link.exe/lld-link/rust-lld/mold/reld as available) with no recompilation between iterations, reporting per-linker medians.
  • Corpus refresh is explicit (version bump), and the mold leg is scoped to Linux.
  • RED -> GREEN: a benchmark run that currently recompiles (or lacks a Bevy corpus), then one that links the frozen corpus repeatedly with zero compile time in the measured loop.

Decisions

  • Priority: P2. Directly improves benchmark realism and iteration speed for the core linker-vs-linker comparison.
  • No LTO, full debuginfo, high codegen-units — deliberately maximizes the linking workload rather than optimization/codegen, so the measurement isolates the linker.
  • Replay the captured real link, not a synthetic --emit=obj, so the corpus reflects an actual Rust final link (objects + rlibs + native/system libs).

Activity

  1. zackees commented on Aug 7, 2026

    @zackees
    CollaboratorAuthor

    Tracked under meta #57 (frozen linker-object benchmark assets — storage/publishing/consumption + manifest.json).

  2. zackees commented on Aug 24, 2026

    @zackees
    CollaboratorAuthor

    Superseded by #70 and delivered in #71. We intentionally adopted one small idiomatic Rust workspace instead of a Bevy-scale frozen corpus: inputs are compiled once per platform/configuration, the target-correct final link is captured and replayed, and only linking is timed. The merged implementation and published evidence satisfy the useful compile-once/link-only objective without the storage and maintenance burden proposed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions