Build with a pinned nightly; a fast profile cuts a rebuild from minutes to half a minute #124

Merged
sionzee merged 1 commit from nightly-toolchain into main 2026-11-21 22:38:46 +01:00
Owner

Based on main, independent of the open stack; it touches no checker code.

Two things made work on this repository slow, and one request goes with them.

Every optimised build used the shipped profile. [profile.release] is thin LTO with one codegen unit: right for the binaries on npm, wrong for an edit loop. Measured on a 32-core machine, after a one-line change to the core crate:

Build Time
cargo build --release -p safe_ts_cli 2.5 to 8.5 minutes, on one core
cargo build --release -p safe_ts_napi another 2 to 4 minutes
the same two with the new fast profile about 33 s each
cargo nextest run (dev profile) 8 to 14 s

Anyone who runs the checker on real code after a change, a person or an agent, paid those minutes several times per change, and npm run build pays them twice (the CLI and the addon). CI's test and benchmark jobs paid them on every push.

The toolchain was "whatever stable is current". The request: build with nightly, and rely on the next-generation trait solver, the Polonius alpha borrow checker, the parallel frontend, and what Rust 1.100 stabilised.

What changes

  • rust-toolchain.toml pins nightly-2026-11-18 for local builds, CI and the released binaries. The four workflows read the date from that file, so it is raised in one place.
  • .cargo/config.toml runs the parallel frontend on 8 threads (the nightly's default is 2) and names the next solver and Polonius, so that a toolchain bump which changes a default is a decision and not a surprise. It also sets Cargo 1.100's dependency cooldown: cargo update skips versions published less than three days ago.
  • crates/safe_ts_core/tests/toolchain.rs has one small item per feature that compiles only with it. I checked each the other way round: with -Zpolonius=off the test fails with E0499, with -Znext-solver=coherence with E0277.
  • [profile.fast]: the release profile without LTO, with 16 codegen units. One variable selects it everywhere: with SAFE_TS_PROFILE=fast, npm run build, npm run check, npm run typecheck and the soundness corpus build and use target/fast/. The binary runs about 7% slower. CI's test, benchmark and docs jobs set it (the benchmarks time the JavaScript the transform emits, not the Rust binary); the release does not.

Two things that are easy to get wrong here

  • Where the flags go. Cargo reads build.rustflags only when no target.*.rustflags entry applies. A machine whose own ~/.cargo/config.toml sets flags for its target (a linker, say) would silently drop a [build] entry. The flags are under [target.'cfg(all())'], which Cargo joins with the machine's; cargo build -v shows both on every rustc call.
  • How the thread count is spelled. The announced spelling is --jobs-frontend=8. cargo-xwin, which builds the Windows binaries in the release, copies the configured flags into the target's environment variable; Cargo then joins that with the config entry, and rustc refuses --jobs-frontend given twice. -Zthreads=8 is still accepted and may repeat, so that is what the config uses.

Verified

  • With the pinned nightly and the fast profile, everything CI's test job runs: cargo test --workspace --locked (329 pass), the std tests (378), the soundness corpus, typecheck, the Vite check, the docs build, and bench:check (50 ratios within tolerance).
  • The shipped profile still builds under the new settings, and cargo xwin check for x86_64-pc-windows-msvc passes for the CLI and the addon.
  • Not verified here: the Linux ARM and macOS cross-builds of the release (zig is not installed on this machine). The release workflow's dry run (workflow_dispatch) covers them; run it once before the next tag.

Not in this change

Using the new library APIs in existing code. The candidates are few (25 strip_prefix(..).unwrap_or(..) that become trim_prefix / trim_suffix, 10 hand-written scope guards that could be DropGuard), and a sweep through the checker now would conflict with every open pull request. New code can use them from here on; the sweep can follow once the stack has landed.

Created with Claude Fable 5.2 in Claude Code.

Based on `main`, independent of the open stack; it touches no checker code. Two things made work on this repository slow, and one request goes with them. **Every optimised build used the shipped profile.** `[profile.release]` is thin LTO with one codegen unit: right for the binaries on npm, wrong for an edit loop. Measured on a 32-core machine, after a one-line change to the core crate: | Build | Time | |---|---| | `cargo build --release -p safe_ts_cli` | 2.5 to 8.5 minutes, on one core | | `cargo build --release -p safe_ts_napi` | another 2 to 4 minutes | | the same two with the new `fast` profile | about 33 s each | | `cargo nextest run` (dev profile) | 8 to 14 s | Anyone who runs the checker on real code after a change, a person or an agent, paid those minutes several times per change, and `npm run build` pays them twice (the CLI and the addon). CI's test and benchmark jobs paid them on every push. **The toolchain was "whatever stable is current".** The request: build with nightly, and rely on the next-generation trait solver, the Polonius alpha borrow checker, the parallel frontend, and what Rust 1.100 stabilised. ## What changes - **`rust-toolchain.toml` pins `nightly-2026-11-18`** for local builds, CI and the released binaries. The four workflows read the date from that file, so it is raised in one place. - **`.cargo/config.toml`** runs the parallel frontend on 8 threads (the nightly's default is 2) and names the next solver and Polonius, so that a toolchain bump which changes a default is a decision and not a surprise. It also sets Cargo 1.100's dependency cooldown: `cargo update` skips versions published less than three days ago. - **`crates/safe_ts_core/tests/toolchain.rs`** has one small item per feature that compiles only with it. I checked each the other way round: with `-Zpolonius=off` the test fails with E0499, with `-Znext-solver=coherence` with E0277. - **`[profile.fast]`**: the release profile without LTO, with 16 codegen units. One variable selects it everywhere: with `SAFE_TS_PROFILE=fast`, `npm run build`, `npm run check`, `npm run typecheck` and the soundness corpus build and use `target/fast/`. The binary runs about 7% slower. CI's test, benchmark and docs jobs set it (the benchmarks time the JavaScript the transform emits, not the Rust binary); the release does not. ## Two things that are easy to get wrong here - **Where the flags go.** Cargo reads `build.rustflags` only when no `target.*.rustflags` entry applies. A machine whose own `~/.cargo/config.toml` sets flags for its target (a linker, say) would silently drop a `[build]` entry. The flags are under `[target.'cfg(all())']`, which Cargo joins with the machine's; `cargo build -v` shows both on every rustc call. - **How the thread count is spelled.** The announced spelling is `--jobs-frontend=8`. cargo-xwin, which builds the Windows binaries in the release, copies the configured flags into the target's environment variable; Cargo then joins that with the config entry, and rustc refuses `--jobs-frontend` given twice. `-Zthreads=8` is still accepted and may repeat, so that is what the config uses. ## Verified - With the pinned nightly and the fast profile, everything CI's test job runs: `cargo test --workspace --locked` (329 pass), the std tests (378), the soundness corpus, `typecheck`, the Vite check, the docs build, and `bench:check` (50 ratios within tolerance). - The shipped profile still builds under the new settings, and `cargo xwin check` for `x86_64-pc-windows-msvc` passes for the CLI and the addon. - **Not verified here:** the Linux ARM and macOS cross-builds of the release (zig is not installed on this machine). The release workflow's dry run (`workflow_dispatch`) covers them; run it once before the next tag. ## Not in this change Using the new library APIs in existing code. The candidates are few (25 `strip_prefix(..).unwrap_or(..)` that become `trim_prefix` / `trim_suffix`, 10 hand-written scope guards that could be `DropGuard`), and a sweep through the checker now would conflict with every open pull request. New code can use them from here on; the sweep can follow once the stack has landed. Created with Claude Fable 5.2 in Claude Code.
Build with a pinned nightly, and a fast profile for the edit loop
All checks were successful
Tests / test (pull_request) Successful in 4m32s
Benchmarks / bench (pull_request) Successful in 2m6s
c6b66d4d56
The repository built with whatever stable was current, and every build that was not a
test used the shipped profile (thin LTO, one codegen unit): after a one-line change to
the core crate that is minutes of one core, several times per change for anyone running
the checker on real code.

- rust-toolchain.toml pins nightly-2026-11-18; the four workflows read the date from it.
- .cargo/config.toml runs the parallel frontend on 8 threads and names the next trait
  solver and the Polonius alpha borrow checker, under a target cfg so that a machine's own
  per-target flags are joined with them instead of replacing them. It also sets a
  three-day dependency cooldown (Cargo 1.100).
- crates/safe_ts_core/tests/toolchain.rs stops compiling when one of those is off.
- [profile.fast]: the release profile without LTO and with 16 codegen units. One
  variable, SAFE_TS_PROFILE=fast, makes `npm run build`, `check`, `typecheck` and the
  soundness corpus build and use it. CI's test, benchmark and docs jobs set it; the
  release keeps the shipped profile.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
sionzee deleted branch nightly-toolchain 2026-11-21 22:38:46 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Evobug/Safe-Ts!124
No description provided.