‹ 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. jerf · · focus · HN ↗
      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.

      1. ch4s3 · · focus · HN ↗
        Yeah doing optimizations in a compiler on things like loops, addition, or string layouts is never free.
        1. [deleted] · · focus · HN ↗

          [deleted]

      2. ModernMech · · focus · HN ↗
        And since you bring up Go and contrast the compile time with Rust, it&#x27;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: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?t=27012&amp;v=6mZRWFQRvmw&amp;feature=youtu.be" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?t=27012&amp;v=6mZRWFQRvmw&amp;feature=...

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

        1. gpm · · focus · HN ↗
          I don&#x27;t think that follows - just that compile times aren&#x27;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).
          1. ModernMech · · focus · HN ↗
            But it can&#x27;t go to zero, that was the point -- at some level you have to pay for what you get. I&#x27;m not saying the compile times couldn&#x27;t be better, but Rust can&#x27;t be Go in terms of compile times if it wants to offer the guarantees and options it does. Meanwhile if Go wants to offer more options and stronger guarantees, it won&#x27;t be able to preserve the short compile times everyone points to.
            1. vlovich123 · · focus · HN ↗
              The Cranelift backend is extremely fast. Most of the slowness is all the crazy optimizations that LLVM does + other things (generating debug info etc).
              1. estebank · · focus · HN ↗
                For symbol heavy projects, linking is a surprising bottleneck.

                Some ideas to speed up compilation by not evaluating items that are not used might pan out significantly for big crates in your dep tree (that behavior might never be stable because that would allow items with compile errors in a crate that would still let your application compile, which is against the Rust approach). The same work to do that would also allow overlapping of crate evaluation between different rustc instances called by cargo, as it would require partial evaluation of crates (to do name res only and gather the symbols needed from its deps).

                Another thing is that stable rust doesn&#x27;t treat macros as idempotent (because that wasn&#x27;t a requirement from the start, there are crates that do dynamic IO to generate types), but if they are then incr comp can be faster by not evaluating them unnecessarily.

                I know people are working on a bunch of different strategies to improve both first and incremental compile times, and I&#x27;m looking forward to the fruit of their labor.

                Compile times are rarely the bottleneck for me, but that doesn&#x27;t mean I won&#x27;t welcome any improvements on that front.

                1. nicoburns · · focus · HN ↗
                  &gt; For symbol heavy projects, linking is a surprising bottleneck.

                  Is that still true with modern linkers like `wild`? Seems like it can link Chromium in 1-2s.

                  &gt; Another thing is that stable rust doesn&#x27;t treat macros as idempotent

                  This seems absolutely insane to me given how pervasive macros are in Rust (I wonder how much of incremental compilation time is just repeated serde derives?). Obviously we can&#x27;t just blindly treat all macros as idempotent, but an opt-in attribute on a macros that pinky-promises that it is seems like it ought to be pretty easy to implement?

                  Maybe somebody&#x27;s looked into it and it doesn&#x27;t help much? But I&#x27;ve heard (unverified) rumours of the opposite.

                  1. estebank · · focus · HN ↗
                    &gt; Is that still true with modern linkers like `wild`? Seems like it can link Chromium in 1-2s.

                    Wild improves things significantly, but it really depends on the kind of project. For some a third of the time can be linking. And not everyone configures their environment to use a different linker. Another thing that can easily improve performance is changing the global allocator, but I&#x27;ve seen teams that measured 10% perf improvements in their own metrics decide against going with anything other than the &quot;default&quot;.

                    I fully expect that if wild delivers an effective incremental linking architecture, then rustc will be able to produce the patches directly (instead of wild having to produce patches from two versions of the object files), which would mean both that rustc is producing less LLVM bytecode and that wild gets to do what it (will) do best and make linking as fast as mechanically possible.

                    &gt; This seems absolutely insane to me given how pervasive macros are in Rust

                    There was some work done on this front, but I haven&#x27;t kept up to date on the current status of that. There was a PR showing promise <a href="https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;pull&#x2F;129102" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;pull&#x2F;129102 (later landed as <a href="https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;pull&#x2F;145354" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;pull&#x2F;145354, 10% on a specific serde-heavy crate, reports of 32% improvements in the original PR). The tracking issue doesn&#x27;t have any updates <a href="https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;issues&#x2F;151364" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;issues&#x2F;151364, but you can try out nightly with -Zcache-proc-macros to see what the effect could be on your projects.

                    Part of the problem I see is that crates will have to opt-in (and we might be able to change the default over an edition boundary) to get the perf benefit, and it might require a granularity lower than &quot;a crate&quot; (which would complicate implementation). I haven&#x27;t seen additional discussions around these design considerations (needed to stabilize), which will need to happen before people can see progress.

                    Sadly, Rust is, like many open source projects, a show-up-o-cracy: you need a motivated (group of?) individual(s) to deliver a feature to fruition, and if the person driving a feature is fine with using nightly for their purposes, and only needs a subset of a feature, they will drive the feature to that state (lets say 80% completion), and then the feature will linger (until someone else with enough motivation to see the other 80% through shows up). This is exacerbated because the project is unwilling to have 80% solutions on stable unless the state is very clearly not going to preclude other future work, or the path to completion is 100% visible (but if that were the case, then it would have been completed already). So we end up with situations like the Allocator APIs.

                    1. nicoburns · · focus · HN ↗
                      (I did a quick test, and I&#x27;m seeing between 15-20% for <a href="https:&#x2F;&#x2F;github.com&#x2F;servo&#x2F;stylo" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;servo&#x2F;stylo which is a macro-heavy crate. I guess it only matter for crates you&#x27;re actually editing though, macro will already be cached as part of &quot;entire crate is unchanged&quot;)

                      &gt; Another thing that can easily improve performance is changing the global allocator, but I&#x27;ve seen teams that measured 10% perf improvements in their own metrics decide against going with anything other than the &quot;default&quot;.

                      Yeah, although I think there&#x27;s more of a trade-off there. Alternative allocators can add significant amounts of compile time. Whereas, modulo maturity, I think a faster linker is more of a pure win. I would imagine we will make wild the default linker at some point if development continues on the trajectory it seems to be on.

              2. dicytea · · focus · HN ↗
                Cranelift&#x27;s biggest blocker for me is that it completely breaks debuggers:

                <a href="https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rustc_codegen_cranelift&#x2F;issues&#x2F;166" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rustc_codegen_cranelift&#x2F;issues&#x2F;...

                1. dabinat · · focus · HN ↗
                  I’m not sure if Cranelift support will ever become stable. It’s really complex, it has tradeoffs like you mentioned, and it requires its own backend to be maintained. TPDE looks like something that could more realistically be stabilized as it just slots into the existing LLVM support.
      3. jchw · · focus · HN ↗
        Rust wants badly to have its cake and eat it too. I get it, but it&#x27;s not the sensibilities I have. The rustc compiler, if it really can achieve everything all at once, will be a beast like none other, making C++ compilers look simple by comparison.

        I&#x27;d love something halfway. Go is maybe a bit radical in some regards, but also, with the news of the new SIMD package for Go, it has occured to me just how little I missed having things like, say, autovectorization.

        (I know also that some people have tried halfway, but the big thing is figuring out how to keep a relatively simple type system that can still support a borrow checker. Even if there is some middleground, is it truly worth it? As nice as it sounds, I&#x27;ve been more skeptical. Go seems to exist in a very narrow space where its simplifications barely can be made to work.)

        1. oscillonoscope · · focus · HN ↗
          The middle ground is pretty much nim.
      4. pjmlp · · focus · HN ↗
        Nah, the only reason is lack of tooling.

        Instead of Go, you could have reached out to complex languages with fast compilation times like D, OCaml, Haskell, Ada, Delphi, C++.

        All of them have alternative implementations with fast compilation times.

        D, use dmd for fast development workflows, gdc or ldc for the ultimate performance at the expense of compilation times.

        OCaml, use the REPL or bytecode interpreter for fast development times, the full blow compiler for ultimate performance.

        Haskell, use the REPL, GHCi for the fast development cycles, GHC for the release build.

        Ada and Delphi, have had fast implementations since forever, although Ada&#x2F;SPARK is indeed somehow expensive.

        C++, yes it isn&#x27;t a mistake. Use Live++, VS hot reload, coupled with binary libraries, or a REPL like CINT (nee ROOT), binary libraries for dependencies, incremental compilation and incremental linking for the development workflow.

        The problem with Rust isn&#x27;t the language itself, rather the ecosystem currently lacking such kind of options being available.

        1. Shorel · · focus · HN ↗
          Dlang is my weapon of choice and I prefer it to rust.
        2. [deleted] · · focus · HN ↗

          [deleted]

        3. slopinthebag · · focus · HN ↗
          including c++ with all of those qualifiers would be like me saying rust is fast with sccache, subsecond, cranelift, and making every single module a separate crate.
          1. pjmlp · · focus · HN ↗
            The difference being the adoption culture across the ecosystem.

            C++ game engines also don&#x27;t need Bevy like tutorials, because most studios aren&#x27;t compiling them from scratch, and tools like Live++ or VC++ hot reload are relatively easy to use.

            1. slopinthebag · · focus · HN ↗
              unreal engine is compiled from scratch (depending on your definition of &quot;from scratch&quot;) and has notoriously long compile times. heck you have to recompile the editor to make certain gameplay code changes. and it&#x27;s by far the most popular AAA game engine on the planet. if it was so easy to fix with your suggestions they would have done it already.

              but hey, just add subsecond and switch to cranelift. problem solved :)

              1. pjmlp · · focus · HN ↗
                Unreal Engine has an installer, and they have done my suggestions, as they are the main customers of Live++ [0], advocates of tooling like Blueprints and now Verse for doing full games.

                Many studios have delivered games with little to no changes to the underlying C++ code.

                [0] - <a href="https:&#x2F;&#x2F;dev.epicgames.com&#x2F;documentation&#x2F;unreal-engine&#x2F;using-live-coding-to-recompile-unreal-engine-applications-at-runtime" rel="nofollow">https:&#x2F;&#x2F;dev.epicgames.com&#x2F;documentation&#x2F;unreal-engine&#x2F;using-...

                1. slopinthebag · · focus · HN ↗
                  so... c++ compile times are fast, because you can simply not compile c++ and instead use blueprints? seems odd since we&#x27;re talking about c++&#x2F;rust compile times. turns out you can make rust compile times infinitely faster by not compiling it too...

                  but when you do have to compile c++, it can be real slow. maybe not as slow as rust, but it&#x27;s not in the same league as eg. go, c#, zig, etc.

                  ue5&#x27;s hot reload is by no means perfect either - many gameplay code changes require recompiling the editor. exposing c++ properties on a blueprint? recompile. modify a constructor? recompile. changing parameters, return types, or adding&#x2F;removing UFUNCTION or UPROPERTY macros? recompile. you can simply search the web to read the experiences of thousands of ue devs complaining about slow compile times and workflows. it&#x27;s the same with unity btw, search &quot;reloading domain unity&quot;.

                  also verse is not in unreal engine. no studio is using verse for ue games. not sure why you threw that in.

                  i get you love c++ and dislike rust, but you aren&#x27;t really making a good case for c++ when you group it in with other languages that have fast compile times ootb, make arguments that involve not using c++ (like blueprints, lol), and rely on brittle third-party hot-reloading solutions.

                  1. pjmlp · · focus · HN ↗
                    I threw that in, because if you knew Unreal Engine, you would be aware of the roadmap for Unreal 6.

                    No one is saying that C++ compile times are anywhere close to Delphi or D, although they are much better when using modules actually.

                    Rather that C++ ecosystem has a developer culture and tools, that makes compiling from scratch and pure distribution of source code for what is a compiled language, something rare, thus despite its slowness, the average impact is less felt than on Rust projects.

                    1. slopinthebag · · focus · HN ↗
                      the roadmap for late 2027 for an experimental release? where studios will still be using C++ for gameplay code?

                      modules? you mean the thing where 2&#x2F;3 major compilers still only have partial support for? how many major c++ projects are using modules?

                      i get it, you hate rust.

                      1. pjmlp · · focus · HN ↗
                        C++ gameplay code doesn&#x27;t require a full engine build for the most part.

                        Office has been using C++ modules for a while now, I think they are major enough.

                        Nah, I hate lack of tooling, you missed my other examples from languages in the ML family.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.