My last post on the Rust compiler’s performance was two months ago and a lot has happened since then.

127 points•trickypr•about 3 hours ago•62 comments•

62 comments

adamchabout 3 hours 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.
bryanlarsenabout 3 hours 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.

maherbegabout 2 hours ago
I'm surprised the OpenAI Codex team doesn't donate like 10B tokens or something to the Rust team for performance
Aurornis44 minutes ago
OpenAI is a Rust Foundation platinum level donor. They gave straight cash which can go toward paying maintainers, which is better IMO. This actually made a lot of people angry because they saw it as a risk of OpenAI gaining influence or something. Can't make everyone happy.

OpenAI also hands out free subscriptions to open source maintainers: https://developers.openai.com/community/codex-for-oss They're time limited for now, but they've been pretty generous about who gets them. Anyone who can show Rust contributions would have been able to get one before.

maherbeg1 minute ago
That's awesome
rirze13 minutes ago
I tend to disregard anyone who complains about foundational open source being funded like this. As long as the donor doesn't have dictatorial control over the product, why obsess over this?
OG_BMEabout 1 hour ago
LLM written code is disallowed by the rust project policy

https://forge.rust-lang.org/policies/llm-usage.html

sigmar16 minutes ago
LLMs are useful in engineering even if the PRs don't include LLM-written code.

>I’m still writing all my own code and text, because (a) that’s paramount, and (b) the project policy requires it, but I had useful LLM analysis assistance on several of the PRs mentioned in this post.

from the article

poly2itabout 1 hour ago
godwinson__4-820 minutes ago
Both OpenAI and Anthropic have robust programs for free tokens that you can apply to if you are a significant enough oss maintainer.

What you suggest may thus be more or less already happening.

echelonabout 1 hour ago
This is one of the most important objectives in software today.

Rust is the best language to serialize agentic LLM output to. It's native, well constructed, low-defect due to design. It's also easy for humans to read and debug if necessary.

The biggest problem with Rust is the compile times. The cycle has to get faster. And we need to start thinking about making the artifact cache non-blocking so multiple agents can work simultaneously - that'll be a big task, but essential if we want to speed up work on one machine rather than spinning up clusters of agent sandboxes (the alternative, perhaps superior solution).

nicoburns43 minutes ago
If you have fast enough hardware then Rust compile times are already not that big of a deal.
Suracabout 3 hours 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?

jerfabout 2 hours 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.

jchwabout 1 hour ago
Rust wants badly to have its cake and eat it too. I get it, but it'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'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've been more skeptical. Go seems to exist in a very narrow space where its simplifications barely can be made to work.)

pjmlp36 minutes ago
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/SPARK is indeed somehow expensive.

C++, yes it isn'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't the language itself, rather the ecosystem currently lacking such kind of options being available.

ch4s3about 2 hours ago
Yeah doing optimizations in a compiler on things like loops, addition, or string layouts is never free.
ModernMechabout 2 hours 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.

pornelabout 2 hours 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).

sigbottleabout 1 hour ago
Is there any experimentation with new ABIs? I mean certain linker flags like --f-lto literally hijack the linker protocol to dump an AST into the backend.

At least for the fully static binary part of rust, there should be some optimizations there w.r.t. compilation. Sure you're not going to interface with shared libraries well but maybe a small experimental feature for fully owned projects? Idk.

weinzierlabout 2 hours ago
I once heard (and don't know if it's still true) that the biggest compile-time sinks are macros and codegen.

Both are kind of outside the Rust compiler's influence. Macros can be almost arbitrarily complex: you pay for what you order. Codegen is LLVM, and that's a fixed choice. You can use Cranelift to get around it, but then you pay elsewhere.

Also, generics and monomorphization regularly come up in these discussion, while common wisdom seems to be that cost for the additional static analysis over other languages like C++ is no a major contributor.

Regardless, it's nice to see performance improvements in the compiler, even if you have to cooperate to benefit from them (e.g. by keeping your macros light and use less generics).

senderista21 minutes ago
Ultimately it's the fact that compile time was not a first-class consideration during the design of Rust's important features. There's only so much you can do to mitigate the consequences.
thevinterabout 2 hours 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.

Joker_vDabout 1 hour ago
> the fact that the article talks about "speeding up" the rust compiler doesn't automatically mean that the compiler is "slow"

Well, if it weren't "slow" for some definition of "slow", nobody would bother speeding it up, would they?

flipping_beacon35 minutes ago
Where I live it's October already will this work now

Read the full thread on Hacker News →

Related stories