How to speed up the Rust compiler in September 2026

(nnethercote.github.io)

45 points | by trickypr 1 hour ago

5 comments

  • adamch 36 minutes ago
    I'm glad to see the donations from big companies to open source maintainers are making measurable difference to the Rust experience. Telling these companies that their employees spend 5% less time waiting for compilation might motivate future investment in people like Nick and the others mentioned.
  • bryanlarsen 31 minutes ago
    Really nice to see that the 5% speedup is despite making the borrow checker better, validating code that previously would have tripped it up.

    Sometimes we really can have our cake and eat it too.

  • torutofu 1 hour ago
    Incremental seems to keep winning the easy wins, so the interesting part is whether the remaining compile-time still lives in the same places as last year.
  • Surac 42 minutes ago
    Why is the compiler slow in the first place? I have no rust knowledge, how slow us slow, lets say in comparison to a c compiler?

    What is the performance killer?

    • kreco 0 minutes ago
      Not sure why you are being downvoted here.
    • jerf 26 minutes ago
      Doing stuff isn't free. For instance, Go compiles relatively quickly for a modern language, but the biggest reason for that is that it does less stuff than most compilers... less optimization, less checking, and some stuff built into the language to avoid some of the problems with having to read lots of headers just to compile a file and other ways of doing less stuff, but mostly the key is it does less stuff, in both the good and bad senses of that.

      If you want something like Rust that offers guarantees and checks and cross-checks by the boatload, it adds up. Macros, monomorphization, implicit code generation with traits and all those other things add up too. And you can't always get O(n) or O(n log n) code to implement those checks. Maybe it can be sped up and maybe there's tricks here or there, but at the Pareto frontier, a language that has more checks will be slower to compile than one that has fewer.

      And that's not a bad thing or a deficit in Rust, it's just the nature of the beast.

      • ch4s3 24 minutes ago
        Yeah doing optimizations in a compiler on things like loops, addition, or string layouts is never free.
      • ModernMech 23 minutes ago
        And since you bring up Go and contrast the compile time with Rust, it's been experienced at Google (and also Volvo and other places) that Rust and Go teams are as productive whereas C++ is less than half as productive: https://www.youtube.com/watch?t=27012&v=6mZRWFQRvmw&feature=...

        So the focus on Rust compile time is misplaced. It's not a big deal in terms of overall productivity.

        • gpm 3 minutes ago
          I don't think that follows - just that compile times aren't the only thing that matters. Maybe rust could be twice as productive as go if compile times went to zero for instance (or maybe not - just disputing that the evidence proves the claim here).
    • thevinter 27 minutes ago
      First of all, the fact that the article talks about "speeding up" the rust compiler doesn't automatically mean that the compiler is "slow"[0].

      Now, is rustc slower than e.g. clang? by how much? why?

      Those are different (and complicated) questions. It really depends on what you're compiling, but I'd say rustc can be 1-5x slower (maybe more at times?).

      The reasons are many and varied, but in general rust compilation is slower because the compiler is doing way more things compared to C (monomorphization, complex trait resolution + type inference, borrow checker..)

      [0]: Also I'd argue that "slow" without a concrete point of reference is a meaningless term in this context.

    • pornel 21 minutes ago
      Zero-cost abstractions aren't zero cost in compilation time. High-level abstractions translate to a lot of boilerplate that the compiler has to optimize out.

      In unoptimized builds often the linker is the bottleneck. Rust/Cargo can parallelize most of the build, generating tons of code and debug info, but then the poor linker has to consume all of it at once. The object/exe formats were designed in ancient times, so they're hard to build incrementally or in parallel (some linkers are trying).

    • JMKH42 37 minutes ago
      Its similar to C++ compilers, there is no one reason. It is a language that tries to optimize a lot, its a big language, it does safety checks, it uses llvm which is a bit slow, its a language that makes use of generics which generate extra code etc etc.
    • ModernMech 29 minutes ago
      It's doing static analysis that many other languages don't do at compile time.
      • dralley 22 minutes ago
        This is not actually the main reason, most of the time.

        Generics/monomorphization and how iterators work results in a lot of compiler bytecode that has to be churned through. More bytecode = longer compilation. It increases the size of the (debug) binaries, the debuginfo in general, causes performance issues with debug binaries in some situations unless you bump the optimization level, causes more IO, etc.

        • ModernMech 18 minutes ago
          Okay but if you don't use generics and monomorphization, then what explains it?
          • dralley 6 minutes ago
            It's unlikely that many people are using Rust without using Option<T> or Result<T, U> a fair bit. Idiomatic Rust fundamentally uses a lot of generics. And a basic for loop expands into quite a large Iterator trait implementation.
  • Citrusoff 56 minutes ago
    The EverInitializedPlaces example really stands out. Going from ~1.5M to ~90K apply_effects_in_block calls by changing the CFG traversal is a reminder that the biggest compiler optimizations often come from changing the algorithm, not optimizing the hot loop itself.

    It also seems like the new Polonius/trait-solver work is pushing compiler performance toward a more interesting problem: doing expensive analysis only when it is actually needed.

    4.57% mean wall-time reduction across 629 benchmarks in two months is pretty remarkable. Great progress.

    • embedding-shape 40 minutes ago
      > reminder that the biggest compiler optimizations often come from changing the algorithm, not optimizing the hot loop itself.

      Isn't this true for most optimizations, not just in compilers? My usual goto process for optimizing is "Find stuff we're doing that we don't have to do, re-evaluate what data structures we use and then re-evaluate what algorithms we use" basically, with minor changes depending on the results. Served me well so far, and haven't (intentionally) written any compilers.