Repository navigation
build: enable parallel rustc frontend via -Zthreads=8 - #30761
sosukesuzuki wants to merge 1 commit into
Conversation
Cargo parallelizes across crates and rustc already parallelizes codegen across codegen-units, but each crate's frontend (parse, macro expansion, name resolution, type/borrow check, MIR) runs single-threaded by default. The workspace crate graph is a funnel: ~110 crates collapse into a few large leaf crates (bun_runtime, bun_css, bun_bundler) that cannot start until their transitive deps finish. The tail of every cargo build is one large crate's frontend pinned to a single core while the rest sit idle. -Zthreads=8 parallelizes that frontend. Nightly-only, but the toolchain is already pinned to nightly and the build already passes -Zbuild-std, -Zsanitizer, and -Zlocation-detail.
|
Updated 3:22 AM PT - May 15th, 2026
❌ @sosukesuzuki, your commit 33c4c8c has 1 failures in 🧪 To try this PR locally: bunx bun-pr 30761That installs a local version of the PR into your bun-30761 --bun |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThis PR adds the nightly-only rustc flag ChangesRust build parallelization
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
LGTM — straightforward build flag addition consistent with the other nightly -Z flags already in this file.
Extended reasoning...
Overview
This PR adds a single rustflag, -Zthreads=8, to the CARGO_ENCODED_RUSTFLAGS assembled in scripts/build/rust.ts. It enables rustc's parallel frontend to speed up the tail of cargo builds where large leaf crates (bun_runtime, bun_css, bun_bundler) are compiled serially. The change is two lines (one comment, one rustflags.push) inserted alongside the existing -Ctarget-cpu push.
Security risks
None. This is a build-system-only change that affects compiler parallelism, not the semantics of generated code. It touches no auth, crypto, network, or runtime logic.
Level of scrutiny
Low. The file already passes multiple nightly-only -Z flags (-Zbuild-std, -Zsanitizer, -Zlocation-detail, -Zsplit-lto-unit, -Zunstable-options), and the toolchain is pinned to nightly via rust-toolchain.toml, so adding -Zthreads introduces no new toolchain constraint. The flag is appended unconditionally in the same style as -Cforce-frame-pointers and -Cllvm-args=-addrsig just above it, following the established pattern exactly.
Other factors
The worst-case failure mode is a rustc ICE or build regression, both of which CI will surface immediately (the PR description explicitly lists CI green and bun bd as test-plan items). No CODEOWNERS cover scripts/build/. The bug-hunting system found no issues. Given the change is mechanical, self-contained, and only affects build wall-time, this is safe to approve without human review.
| "cortex-a72"; | ||
| rustflags.push(`-Ctarget-cpu=${cpuTarget}`); | ||
| // Parallelize the otherwise single-threaded rustc frontend (nightly-only). | ||
| rustflags.push("-Zthreads=8"); |
There was a problem hiding this comment.
I wonder if it should check os.availableParallelism() and only use if 8+ to avoid overloading on less powerful builds
|
Landed on main via #31096, so closing this one. One difference: #31096 gates -Zthreads=8 on !cfg.ci (local builds only), while this PR enabled it for CI builds as well. #31096 keeps CI on the serial frontend on purpose (stable diagnostic ordering, no -Z flag on shipped builds), so enabling it in CI would be a separate change if anyone wants it. |
Summary
bun_runtime,bun_css,bun_bundler) that cannot start until their transitive deps finish. The tail of every cargo build is one large crate's frontend pinned to a single core while the rest of the machine sits idle.-Zthreads=8parallelizes that frontend. It is nightly-only, but the toolchain is already pinned to nightly and the build already passes-Zbuild-std,-Zsanitizer, and-Zlocation-detail, so this adds no new constraint.Test plan
bun bdcompletes successfully (full debug build, no rustc ICE)bun-debugruns (--revisionand a basic JS eval)-Zthreads=8is present in the cargoCARGO_ENCODED_RUSTFLAGSof generatedbuild.ninja