VOOZH about

URL: https://thenewstack.io/where-does-the-time-go-rusts-problem-with-slow-compiles/

⇱ Where Does the Time Go? Rust's Problem with Slow Compiles - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2024-01-25 10:34:40
Where Does the Time Go? Rust's Problem with Slow Compiles
Rust

Where Does the Time Go? Rust’s Problem with Slow Compiles

Frustrated by the slow build times of their Rust programs, the engineering team at Oxide investigated the entire compile process.
Jan 25th, 2024 10:34am by Joab Jackson
👁 Featued image for: Where Does the Time Go? Rust’s Problem with Slow Compiles
Feature crab by Dmitry Abramov from Pixabay.

While many are sold on the magic of the Rust programming language, one persistent complaint keeps popping up: the long time it can take to compile Rust programs.

“I really feel like the Rust community suffers from a collective Stockholm Syndrome when it comes to compile times. They are bad. I know it’s hard work to fix this, but the compiler is very far off of what good productivity demands,” wrote Armin Ronacher, creator of Python Flask, on X (the platform formerly known as Twitter). His criticism of Rust’s slow build times has been one of many.

On Monday, Oxide held a virtual meetup on Discord to discuss the issue.

The Zen of Compile Time

Oxide CTO Bryan Cantrill is no stranger to long compile times.

He recalled at one point in his time at Sun Microsystems that compiling an OS kernel would take more than 24 hours to complete. That was a bit outrageous, he admits satisfaction from a lengthy build, appreciating that “it’s taking a long time to compile because it’s solving really hard problems for me.”

But he acknowledges there is also an inherent frustration with long build times, a sinking feeling that this is time better spent elsewhere, both for man and machine.

“One of the things that’s most frustrating is when you, the programmer, really feel like Rust is doing work it doesn’t need to do,” Cantrill said.

So the company set its engineers on the task of trying to figure out why Rust apps took so long. As this online discussion revealed, it turned out to be quite the side quest…

“Why is my compile taking so long?!” If you are a Rust programmer, you have asked yourself this question many times. Tomorrow, @ahl and I will be joined by our colleagues Sean Klein and Rain Paharia to dig into Rust build times. Join us, 5p Pacific! https://t.co/X7p4dlD5IU

— Bryan Cantrill (@bcantrill) January 21, 2024

How Oxide Uses Rust

A hardware company specializing in gear for on-premises clouds, Oxide used Rust to build its control plane (“Omicron“) as well as other infrastructure software (everyone at Oxide seems to love the advanced capability of Rusts packaging system, Cargo).

These projects started small but as they grew larger, their compile times slowed. This could be particularly frustrating when making a single change and looking to see the results, which involves lots of repeated builds, Cantrill said.

Worse, as the compile times grew, it made became increasingly more difficult which parts of the build were gobbling up all the time. Build times could not be shortened if there were no tools to reveal why they were taking so long to build in the first place.

The Rust compiler was written as a classic batch compiler (though it has been expanded with some incremental capabilities) meaning you have to sit through the compile time of the entire app, even if you only made an incremental change. Hit cargo-build, and the resulting build time could go for 48 seconds or three minutes or longer. But the programmer will only stay for so long before doing something else entirely, breaking up their flow, Cantrill observed.

How Rust Compiles Code

cargo build –timings has a flag that, when called, provides a build graph of, crate by crate, what is being built, and how long it takes to build each one.

What is happening inside these crates remains a bit of a mystery though, and so can be a challenge to optimize for, said Oxide software engineer Sean Klein, “There is not one answer for where you go next. There’s a lot of different answers,” he said.

Tools like cargo-llvm-lines, or cargo-bloat can show why the resulting binaries are the size they are, but these measurements are proxies for estimating compile times themselves.

One obvious issue in Monomorphization, which is either a feature or a bug of Rust, depending on how you look at it. If a small generic function is used in multiple places across an application, Rust will compile that generic for each specific case. Result: Fast programs, slow compile times.

Oxide engineer Steve Klabnik created a 10-line function that eliminates all these repeat builds of generics. “By making this small change, you can help the compiler not do as much work,” the pull request documentation reads. It shaved five seconds from the build time of Omicron.

Also working on this issue is Oxide engineer Rain Paharia, who has spent a lot of time looking at the issue, both at Oxide and at their previous role at Meta.

When a crate is rebuilt, then all of its dependents are also rebuilt transitively, they said.

For instance, the widely used syn-crate, a parsing library has about 15 features, any number of which may be called by a program’s Procedural Macros (a handy to feature used to extend program code at compile time).

At compile time all those features get rebuilt, regardless of which ones are actually called…

“All of a sudden, you have this combinatorial explosion of feature or feature sets that can be built. And because syn is so core, every single thing that depends on syn, also gets rebuilt,” Paharia said. “It is kind of a disaster scenario at the moment. This is not good at all.”

Problem Solved?

Paharia built some tooling that works around the problem, such as cargo-hakari, a command-line application that uses a blank crate to speed compilations by 20-25%. The crate specifies a union of all the features used everywhere in the program, so they are compiled only once, instead of multiple times.

They found that cargo-hakari cut build times somewhat … but not entirely. So Paharia dug in with a new (unstable) Rust feature called the unit graph, which specifies each atomic step in the build process, building off the dependency graph for the app.

Pouring over the output, Paharia found that, despite their preventive measures, the compiler was still rebuilding many duplicate objects, due to a variety of obscure behaviors, such as how Rust handles panics for plug-ins, and how Rust handles Proc Macros in general.

Also, importing non-Rust code, through Build Scripts, can consume hella resources. The Oxide team also seems to collectively love Build Scripts, even as they suffer through the performance hits they incur.

Work Still to be Done on Rust Compile Times

Rust does have a “self-profiling” flag that will let you know how long it take to build a particular macro. It provides, as JSON, a timeline of how long each action took, in terms of ” internal compiler passes,”  which is not that useful without a lot of subsequent analysis

“It’s a little informative, but it’s not as informative of as like, which module were you working on?” Klein said. he noted that there is a lot more tooling that still could be built around this output, which would provide more insight into compile times.

So why are your Rust compile times so slow? Eightball says: check back later.

The full discussion can be enjoyed here:

(Update: The post has been updated with Sean Klein’s correct name)

TRENDING STORIES
Joab Jackson is a senior editor for The New Stack, covering cloud native computing and system operations. He has reported on IT infrastructure and development for over 30 years, including stints at IDG and Government Computer News. Before that, he...
Read more from Joab Jackson
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.