How to speed up the Rust compiler in December 2025

2025年12月5日

AI 摘要 AI 生成,可能有误

本文回顾了截至2025年12月Rust编译器的近期性能改进,包括诸如为平凡常量(trivial consts)的降级提供快速路径(使 libc crate 的编译速度提升 5-15%)、对 format_args!() 更节省空间的重新实现、升级至 LLVM 21,以及减少 rustdoc-json 中的内存分配等优化。文章还描述了精简 Bevy 中由 #[derive(Reflect)] 过程宏所生成代码的工作,使生成的代码体积减少 39%,编译时间缩短 16%。总体而言,自5月以来,平均实际耗时(wall-time)改善了约 2.65% 至 3.19%,而内存使用量和二进制文件大小等其他指标的表现则好坏参半。

It has been more than six months since my last post on the Rust compiler’s performance. In that time I lost one job and gained another. I have less time to work directly on the Rust compiler than I used to, but I am still doing some stuff, while also working on other interesting things.

Compiler improvements

#142095: The compiler has a data structure called VecCache which is a key-value store used with keys that are densely-numbered IDs, such as CrateNum or LocalDefId. It’s a segmented vector with increasingly large buckets added as it grows. In this PR Josh Triplett optimized the common case when the key is in the first segment, which holds 4096 entries. This gave icount reductions across many benchmark runs, beyond 4% in the best cases.

继续阅读全文

为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

更多来自 Nicholas Nethercote

How to speed up the Rust compiler in November 2026

AI 摘要The article reviews a month of Rust compiler performance work, highlighting a new span compression scheme that cut interning to ~1% for incremental builds and reduced instruction counts by up to 3%+, along with a dozen micro-optimizations that lowered the new trait solver's overhead on Diesel from 1.49x to 1.16x. Other changes included removing the AttrTokenStream types, avoiding type variables in large vec literals, and sparse metadata encoding that shrank metadata by up to 37% and peak memory by up to 7%. Overall, the period saw a 2.85% mean wall-time improvement and a 4.46% mean max-RSS reduction, with 560 of 561 instruction-count measurements since the start of the year showing improvements.

How to speed up the Rust compiler in September 2026

AI 摘要The article reports that the Rust compiler achieved a mean wall-time reduction of 4.57% between late July and late September 2026, with 555 of 629 benchmarks improving. Key contributors included enabling PGO for Clippy, upgrading to LLVM 23, optimizations for the new Polonius Alpha borrow checker and new trait solver, and numerous improvements from contributors like xmakro and the author, including a ~30% speedup for cranelift-codegen via a new CFG traversal algorithm. The author also notes they will soon start working at Hexcat on compiler performance optimization.

How to speed up the Rust compiler in July 2026

AI 摘要This July 2026 update on Rust compiler performance reports a 5.59% mean wall-time reduction since December 2025, driven largely by a 37.92% improvement in rustdoc (from optimized impl processing, PGO training, and faster impl sorting) plus major Clippy speed-ups from eliminating no-op virtual dispatch calls. Additional gains came from incremental compilation tweaks, AST node size reductions, and dramatic new trait solver progress, including one benchmark dropping from 27 seconds to under one second, with notable contributions from newcomers xmakro and arya dradjica. The author also thanks the weekly performance triage crew and shares personal news of leaving their job at VectorWare to pursue paid work on the Rust compiler.

My new job

AI 摘要The author announces they have joined VectorWare, a startup aiming to improve GPU programming with Rust, in a role that involves open source and some Rust compiler work while they remain a Rust compiler team member and maintainer. They clarify that speculation about their delayed announcement was unfounded—the wait was due to paperwork—and that they received interest from many employers, demonstrating Rust's adoption across a remarkably wide range of industries. They close by thanking everyone who helped during their job search.

Faster Rust builds on Mac

AI 摘要macOS's XProtect antivirus feature scans every newly compiled executable for malware, which significantly slows down Rust build scripts, cargo run cycles, and especially test suites that launch many small binaries—for example, the Rust compiler's tests/ui suite dropped from 9m42s to 3m33s when XProtect was disabled. The workaround is to add Terminal as a 'developer tool' in System Settings, though this disables an OS security feature. A draft PR for Cargo would detect when XProtect is enabled and warn users about its performance impact, helping spread awareness of this little-known trade-off.