Skip to content

build: enable rustc parallel frontend (-Zthreads=8) for local builds - #31096

Merged
dylan-conway merged 1 commit into
mainfrom
claude/rust-parallel-frontend-local
May 19, 2026
Merged

dylan-conway merged 1 commit into
mainfrom
claude/rust-parallel-frontend-local

Conversation

@dylan-conway

Copy link
Copy Markdown
Member

rustc's frontend (parse, macro expansion, typeck, borrowck) is single-threaded by default — only the LLVM backend fans out via codegen-units. The Rust crate graph's critical path is a serial chain ending in bun_runtime, so during the tail of every bun bd one core does ~20s of work while the rest idle.

-Zthreads=8 enables rustc's parallel-frontend query pool. It shares cargo's jobserver, so concurrent rustcs don't oversubscribe — each frontend thread acquires a -j token before running. Gated on !cfg.ci so PR/release builds keep deterministic diagnostic ordering and stay off the nightly -Z surface.

Why 8 and not nproc: scaling on bun_runtime (32-core box, debug, no incremental cache):

-Zthreads wall
1 20.2s
4 13.2s
8 10.6s
16 9.6s
0 (=nproc=32) 10.9s

Returns flatten past 8 (macro expansion is inherently serial; the query DAG has its own critical path), and 0 is marginally worse than 8 from sharded-lock contention. 8 is also the upstream proposal for the eventual default (rust-lang/compiler-team#681), so this becomes a no-op when that lands.

Verified: flag present in build.ninja for local configure, absent with --ci=true; bun bd --revision works.

@robobun

robobun commented May 19, 2026 •

Copy link
Copy Markdown
Collaborator
Updated 4:44 PM PT - May 19th, 2026

❌ @dylan-conway, your commit 715a175 has 1 failures in Build #56243 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 31096

That installs a local version of the PR into your bun-31096 executable, so you can run:

bun-31096 --bun

@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9f2eb2d5-6ca4-4538-b65f-3c655af6773a

📥 Commits

Reviewing files that changed from the base of the PR and between 1d227bf and 715a175.

📒 Files selected for processing (1)
  • scripts/build/rust.ts

Walkthrough

This PR conditionally enables Rust's parallel frontend compilation for local development builds. The change appends -Zthreads=8 to the Rust compiler flags only when building outside CI, preserving deterministic behavior in CI and release pipelines while improving build times locally.

Changes

Parallel Rust Frontend Optimization

Layer / File(s) Summary
Conditional parallel rustc frontend for local builds
scripts/build/rust.ts
A !cfg.ci guard appends -Zthreads=8 to CARGO_ENCODED_RUSTFLAGS to enable parallel rustc frontend processing in local builds. Extensive inline comments document why 8 threads are chosen, how jobserver interaction works, and explain why CI and release builds remain on the serial path for determinism and byte-identical outputs.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: enabling rustc's parallel frontend with -Zthreads=8 for local builds, which is the core focus of this PR.
Description check ✅ Passed The PR description covers both required template sections: it explains what the PR does (parallel frontend enablement, why 8 threads, performance data) and how it was verified (flag presence in build.ninja, CI gating confirmation, successful builds).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown
Contributor

This PR may be a duplicate of:

  1. build: enable parallel rustc frontend via -Zthreads=8 #30761 - Also adds -Zthreads=8 to rustflags in scripts/build/rust.ts to enable the rustc parallel frontend

🤖 Generated with Claude Code

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — local-only build flag with clear rationale and CI gating.

Extended reasoning...

Overview

This PR adds a single conditional rustflags.push("-Zthreads=8") to scripts/build/rust.ts, gated behind !cfg.ci. It enables rustc's parallel frontend for local developer builds to speed up the critical-path crate compilation, with a detailed code comment explaining the choice of 8 threads and why CI/release builds are excluded.

Security risks

None. This is a build-script change that only adds a compiler optimization flag for local builds. It does not touch runtime code, auth, crypto, or any user-facing surface.

Level of scrutiny

Low. The change is confined to the build pipeline and explicitly excluded from CI/release via !cfg.ci, so shipped binaries are unaffected. The file already uses several nightly -Z flags (-Zsanitizer, -Zbuild-std, -Zsplit-lto-unit, -Zlocation-detail), and the toolchain is pinned to nightly per existing comments, so adding another -Z flag follows the established pattern. Worst-case failure mode is a local build error, which is easily reverted.

Other factors

The PR description includes benchmark data justifying the thread count, references the upstream compiler-team proposal that will eventually make this the default, and notes manual verification that the flag appears in local build.ninja but not under --ci=true. The change is small (one conditional push + comment), self-contained, and matches the surrounding code style. No bugs were found by the bug-hunting system.

@dylan-conway
dylan-conway merged commit 6aa6923 into main May 19, 2026
29 of 46 checks passed
@dylan-conway
dylan-conway deleted the claude/rust-parallel-frontend-local branch May 19, 2026 21:52
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