‹ BackHN Continuity

Thread

How to speed up the Rust compiler in September 2026

279 points · 171 comments · trickypr

  1. Surac · · focus · HN ↗
    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?

    1. ModernMech · · focus · HN ↗
      It's doing static analysis that many other languages don't do at compile time.
      1. dralley · · focus · HN ↗
        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.

        1. ModernMech · · focus · HN ↗
          If you don't use generics and monomorphization, then what explains it?
          1. dralley · · focus · HN ↗
            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 lot of intermediate representation due to Iterator.
            1. ModernMech · · focus · HN ↗
              Other languages support generics, monomorphization, and iterators (e.g. Zig or D), but they're not as slow as Rust to compile, what's the reason for that?
              1. tialaramex · · focus · HN ↗
                It's likely easier to answer for specific languages

                All three of those words can mean "just like Rust" but equally "Not at all like Rust" for different languages.

                Two examples to contrast: In C++ the iterators are basically a pointer analog (in some cases they're just literally pointers) and that's a very difference "feature" but it's still definitely iterators. In Ginger Bill's Odin, the iterators are a function, possibly generic, which returns a pair, the next item and a boolean telling you whether the iterator was exhausted.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.