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

284 points•trickypr•about 2 months ago•174 comments•

174 comments

knuckleheadsabout 2 months ago
Funny to see this now. I’ve got a private branch I am in the process of shaping up this weekend to show the compiler team. For deep nested projects like rust analyzer, if you emit the meta data about function types earlier for downstream slots to use, before successful type checking, you can start other crates earlier and use all the slots you have instead of sitting around waiting for the full type checking of the bodies (which other crates largely don’t care about). Something like 40% wall time speed up, maybe 10% to 15% if you have the parallel frontend on.
panstromekabout 2 months ago
Nice, excited to see that. This is basically deeper pipelining, IIUC. Nick (the author of the blog) implemented the current version of this "emit metadata sooner," optimization and already experimented with pushing it even sooner a while back.

We have discussed this briefly on last All Hands, the problem will probably be dealing with compiler errors, when they happen in builds that already emitted metadata. I believe this was the reason why it wasn't merged in the first place.

knuckleheadsabout 2 months ago
Yes I think I read a post of his from like 2019 were something was tried like this before. My guess is that this will be an interesting and hopefully informative PR for you all to see, but will likely not be merged as is. I had to add the ability for rustc to pause after early meta data emission and that was hacked together I feel, not well designed per se.

I view this as speculative execution/compilation and just throw out any errors from a crate that depended on another crate that ultimately errors out. It has the same outcome (same errors are printed in both cases) you just have a chance of having totally wasted some cpu time (that was otherwise just sitting around though).

embedding-shapeabout 2 months ago
Sounds lovely, give it a try on the codex-rs which seems to be getting close to using 2K crates in their repository any time now. Takes like 30 minutes to compile on a my beefy machine and it's a goddamn TUI, not sure what's going on, and not too interested in diving into that beast either.
surajrmalabout 2 months ago
It has 1.8 million lines of rust. That compilation time seems close to what I'd expect at that size. If you want something faster you should focus on distributed build caching rather than speeding up the compiler. Also note that crates are effectively equivalent to a single file in c++ as it's the compilation unit. This is similar to compiling 2k files that average 1k loc each in c++. I'm sure it's much worse when you account for macro expansion and generics.
lr1970about 2 months ago
I build it with `cargo build -p codex-cli --bin codex` in under 4 minutes on my old M1 MacBook Pro with 64GB memory compiling more than 1250 crates.
yearolinuxdsktpabout 2 months ago
It’s insane. 45 minutes to build debug from scratch. Linking is super slow even in debug and that’s without LTO.

Incremental compilation is not cleaned up. Older deps pile up and don’t get cleaned.

Run out of disk space? Oh it’s just the 200+ GB codex-rs target folder.

Forget about doing worktrees.

Rust has a lot of work to do.

knuckleheadsabout 2 months ago
This thing is a monster, blows out the disk space on a Claude code web session. Will run it on my test server later and let you know.
adamchabout 2 months 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 2 months 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.

s08148692about 2 months ago
I finally gave in to the rust hype and built a new project in it (or my agent fleet did). Almost instant regret. My poor machine with just 2TB HDD and 24 cores was almost immediately crippled by agents each working in their own sandbox, each one building and compiling

Most projects my fleet works on are in other languages (TS, Go, Elixir) and can comfortably handle 10+ agents working in parallel, but not rust. I had to cap the fleet to 5 workers and build a dedicated resource monitor to step in and tidy up every time the disk almost filled up

That and general progress on building is far slower, with far more time spent building and testing than any other language I use.

Ended up rebuilding in Go, the perf gains weren't worth it

Aurornisabout 2 months ago
You should have set up https://github.com/mozilla/sccache at minimum. Setting up compiler caching is routine for people coming from older compiled language backgrounds but it's often missed by people coming from languages like JS/TS who have never been exposed to these ideas.

There's a new project called kache https://github.com/kunobi-ninja/kache that takes this even further and handles more edge cases with worktrees, but it's newer.

If you were pulling the entire project fresh and rebuilding everything in every worktree all the time without any caching then it would be frustrating. You could have asked your agent to set up basic caching and solved most of your problem in minutes.

slopinthebagabout 2 months ago
this is the issue with vibing...you don't know what you don't know
jiehongabout 2 months ago
Shouldn’t this be part of cargo and enabled by default then ?
jarjouraabout 2 months ago
You really shouldn't build software with rust if your workflow involves 10+ agents. Why aren't you using Python or Typescript for things like that?

Rust is what you use when you want to maximize on the runtime performance. It will build software that requires significantly less memory and maximize the CPU that will save time and energy. It's a system language for writing software meant to access the hardware.

ameliaquiningabout 2 months ago
Why would that imply that you wouldn't use a lot of agents?
paholgabout 2 months ago
Most of that time was probably compiling dependencies. If you give it another go, I would recommend a shared sccache.

https://github.com/mozilla/sccache

pjmlpabout 2 months ago
Even that doesn't fully avoid recompilation of the same crate, due to features changes across the dependency chain.
jbellisabout 2 months ago
A couple recs for sccache, which is great, but I upgraded to mbx (https://github.com/jdx/mr-boxington/) which goes beyond sccache by wrapping cargo to give you better rust-specific management, including incremental compilation.

My harness control plane will autoconfigure mbx across all your machines, if you like. https://github.com/BrokkAi/mjolnir/

slopinthebagabout 2 months ago
first time i've seen rust's compile performance actually act as a filter haha
slowinabout 2 months ago
I've moved from Rust to Go for most things because in the era of agents, being able to iterate quickly on a project is a huge advantage and Rust is way, way slower than Go for compilation. There are times when Rust is more appropriate, but for the vast majority of things Go is perfectly fine.
echelonabout 2 months ago
I nearly did this, but then I swapped to writing native desktop apps and egui - Rust is still worth it.

I've stopped using Tauri and gone with 100% egui. It's cross platform and excellent, and if you give it design constraints it will look beautiful.

Check out my 100% adobe clean room reimplementations:

https://github.com/storytold/filmcraft

https://github.com/storytold/photocraft

https://github.com/storytold/drawcraft (going to rename this vectorcraft)

The #1 thing for the Rust project to do is make Rust faster to compile.

Rust is the agentic AI language. It just needs to lean in and go faster.

shirolabout 2 months ago
Checked out your GitHub profile. This is an insane amount of LLM usage. You created 7 full-blown apps, and each of them is very recent. The earliest commit was only 2 days ago.

I'm normally against fully vibe-coded apps, but at this point, I'm just impressed.

tcfhgjabout 2 months ago
> The #1 thing for the Rust project to do is make Rust faster to compile.

#0 get rid of the orphan rule

mixmastamykabout 2 months ago
Looks great. It's early but how well do they work? Comparable to FOSS apps yet?

Also it says egui is immediate mode, does that use a lot of {C,G}PU or have any other issues?

slowinabout 2 months ago
Very cool projects! I agree, desktop apps are one of the areas that Rust beats Go. It's too bad though, since I feel anything with a heavy GUI like this can benefit from a rapid iteration cycle which is painful with Rust.
nonethewiserabout 2 months ago
Are agents able to control these well? I saw vector craft mention MCP and a command api. Whats the command api? No CLI it sounds like.
Aurornisabout 2 months ago
> because in the era of agents, being able to iterate quickly on a project is a huge advantage and Rust is way, way slower than Go for compilation.

Incremental changes in a normal project shouldn’t cause massive compile times. Even for my large projects, the compile times are trivial compared to the duration of an LLM turn.

Very large projects should be broken into logical modules so only the changed part is incrementally compiled. If linking is taking a long time there are alternate linkers that can be used.

If you’re using work trees a lot, set up compiler caching to avoid rebuilding everything from zero on every new work tree is important.

I know these things are frustrating to new Rust users who just want everything to be automatic and easy, but if we’re talking about LLM development anyway then these optimizations would have come up the first time you asked your LLM what could be done about improving compile times. LLMs are very good at setting up these optimizations.

asutekkuabout 2 months ago
Compile can take minutes on large codebases, LLM turns usually seconds. How are these even comparable?
Bolwinabout 2 months ago
I don't really understand why Rust seems to be the go-to language for llms. Yes sure it has a good type system, but in practice llms seem to trip over it as much as I do, and given how fast llms are at writing code, that just makes compile times a much larger bottleneck.
jeroenhdabout 2 months ago
Go is full of footguns and LLMs still cannot be trusted to follow the rules they themselves conjured up out of thin air. Unlike humans, they don't need to be taught the language (which is the hardest part of using Rust, by far), so they get more benefits out of it than many humans do.

LLMs do trip up when they generate Rust code, but they also do when generating any other language. The big difference is that the Rust compiler refuses to compile broken code faster, whereas Go will just let you SIGSEGV on edge cases without warning.

The recent TLA+ hype here on HN shows that Rust may just be the beginning here. There are valid, safe Rust programs that will crash, the language isn't perfect. The older languages with more math and validation behind them (Ada?) are probably even better suited for generated code, but they don't have the hype culture to capture mainstream attention (and even fewer people have the ability to really review that code).

There's an alternative solution of course: use platforms like JS/.NET/JVMs/Python to run code that cannot violently crash because of the language runtime around it. That comes with a performance overhead but it's good for prototyping without as many stability footguns and with faster compilations.

GuB-42about 2 months ago
Rust and LLMs are a good match.

Rust is built on the idea that code that compile must be correct, to the best of its abilities. LLMs are fast and sloppy, Rust keeps them in check by not letting them get away with preventable bugs.

Of course, Rust can't do anything for spec bugs, like making the stop light green when it should be red, but it can help with crashes and vulnerabilities.

dmeadabout 2 months ago
Isn't this also the reason people dropped Haskell?

Read the full thread on Hacker News →

Related stories