Rust 在 nightly 版本中默认启用并行编译器前端
Rust 编译器团队已在 nightly 渠道默认启用并行前端(自 nightly-2026-11-14 起),作为最终稳定该特性的铺垫。负责类型检查和借用检查的前端此前一直单线程运行,而基于 LLVM 的后端早已支持多线程。三年前官方曾在 nightly 上提供可选的并行前端,并计划于 2024 年稳定,但该目标未能实现;去年启动的协同攻关修复了许多长期存在的问题。
基准测试显示收益显著但差异较大。在单 crate 构建中,使用 8 线程时 cargo check 的耗时降低约 44%,opt 构建降低约 28%,nalgebra、cargo 和 diesel 等 crate 的编译速度接近快三倍。而在 8 核机器上对整个 cargo crate 图做端到端 cargo check 仅提升约 15%,从 36.7 秒降到 30.8 秒,因为后端并行和多 crate 并行编译已经占满 CPU 核心。增量重建的改进较小,平均为 3-5%。
Nightly 默认使用 2 个前端线程,这是为了在发现问题控制内存占用的保守选择。开发者可通过 RUSTFLAGS 或 .cargo/config.toml 中的 --jobs-frontend(需配合 -Zunstable-options)覆盖线程数。超过约 8 线程后性能可能不会很好地扩展,更高的线程数可能增加编译器内存占用,极端情况下会导致内存耗尽。已知问题包括诊断信息顺序不确定以及二进制文件可能不可复现,团队将这些视为 bug 处理。
稳定版用户不受影响,仍使用顺序前端。Nightly 用户可通过 --jobs-frontend=1 退出,团队希望选择退出或遇到崩溃、构建不可复现的人在 GitHub 或 Zulip 上反馈原因。未来几个月团队将监控反馈,在确认稳定后推进稳定化,同时继续优化性能,并将宏展开、名称解析以及 AST 到 HIR 的降级等更多前端阶段并行化。
Rust enables the parallel compiler frontend by default on nightly
The Rust compiler team has enabled the parallel frontend on the nightly channel by default, starting with nightly-2026-11-14, as a step toward eventually stabilizing it. The frontend, which handles type checking and borrow checking, has run on a single thread even though the LLVM backend has long been parallel. An opt-in version was offered on nightly three years ago with a plan to stabilize in 2024, a goal that slipped, but a coordinated effort begun last year has fixed many long-standing issues.
Benchmarks show meaningful but varied gains. For single-crate builds, the frontend reduced wall time by about 44% for cargo check and 28% for opt builds with 8 threads, and some crates such as nalgebra, cargo and diesel compiled almost three times faster. An end-to-end cargo check of the whole cargo crate graph on 8 cores improved only about 15%, from 36.7s to 30.8s, since backend parallelism and parallel crate compilation already saturate cores. Incremental rebuilds saw a modest 3-5% improvement.
Nightly defaults to 2 frontend threads as a conservative choice to limit memory use, and developers can override the count with --jobs-frontend (together with -Zunstable-options) via RUSTFLAGS or .cargo/config.toml. Scaling is unlikely to be good above about 8 threads, and higher counts may raise memory usage, in extreme cases causing out-of-memory failures. Known issues include nondeterministic diagnostic ordering and possible non-reproducible binaries, which the team treats as bugs.
Stable users are unaffected and still get the sequential frontend. Nightly users can opt out with --jobs-frontend=1, and the team asks anyone who does so, or who hits crashes or non-reproducible builds, to report it on GitHub or Zulip. Over the next few months the team will monitor reports, then move to stabilize the feature while also improving performance and parallelizing more frontend stages, such as macro expansion, name resolution and AST-to-HIR lowering.
猎鹰不保存原文正文。标题与摘要用于快速发现信息,事实细节请以来源原文为准。