Rustdoc developer achieves 33% speedup through performance optimization
Noah Lev of the Rustdoc team discovered and fixed inefficient trait impl inlining that was causing stack overflows and slowdowns.
What to know
- Rustdoc's `build_extern_trait_impls` function was unnecessarily inlining trait documentation from all crate dependencies, causing both stack overflow errors and severe performance degradation.
- The fix reduced average wall-time by 25% (33% speedup), with real-world improvements up to 40% and microbenchmark improvements reaching 60%.
- The regression was caught by Crater, Rust's ecosystem-wide testing tool that validates new releases against thousands of public crates before stable release.
- Lev used profiling tools including `-Z self-profile` and flame graphs to identify the bottleneck and measure the impact of his optimizations.
The profiling and debugging approach is exemplary and worth learning from.
-
“This is awesome. Curious on the profiling setup there; flame graphs are something I've been after and haven't found a clear way to get them.”
junon · Lobsters ↗
Crater's ecosystem-wide testing is a best practice that other projects should adopt.
-
“Great idea. Haven't heard of any other docs engines actively validating new releases against their ecosystem. The status quo is more along the lines of "we have a release candidate, please try it and report bugs."”
kaycebasques · Lobsters ↗
“So if Rustc was successfully compiling this code, it was concerning that Rustdoc failed on it.”
Noah Lev, Rustdoc team member · noahlev.org blog · Aug 26
Noah Lev Rustdoc team member@theemathas Rust release team member
The record 1 articles and posts · last 30 days
What people are saying 12 voices from 1 site · verbatim
- Sep 4
-
For sure, getting empirical performance data really helps guide your efforts.
-
Hey, I'm the author of this blog post and a Rustdoc team member. The JSON output is still unstable, though we avoid making breaking changes to it unless deemed necessary (e.g. when there are new language features or big refactors to Rustdoc internals). It is used extensively by popular tools like cargo-semver-checks (cc @predrag). > Didn't find a…
-
Hey, I'm the author of this blog post! Just seeing this thread now. I used perf.rust-lang.org, our internal performance benchmarking website for the Rust compiler and Rustdoc. However, under the hood, it uses a pretty similar setup to what you described, including loading its data into Perfetto.
- Aug 29
-
My current favorite for ease of use is [`samply`](https://github.com/mstange/samply) (I'd compile the code being profiled with release profile/optimizations enabled, updated to add debug information). Can use it with Python too, `samply record python -X perf yourprogram.py` and now it shows Python callstacks too. The main downside is that it…
-
"Look at a flame graph" finds a surprising number of performance problems for many (most?) software projects. I've been finding quite a few of those in scikit-learn, not because they don't care about performance (it's already optimized in many places) but just because they haven't had the resources.
- Aug 28
-
Yes, it builds everything on crates.io and rust repos on Github. There are currently some limitations and exclusions though. The crater runs have finite resources and running a lot of cargo instances in parallel can be resource intensive so sometimes building crates will spuriously fail. Rerunning helps there. There are also crates that require…
-
Thanks, at the very least this is a good jumping off point. I appreciate it!
-
> How much of the ecosystem does Crater test against? It depends. At maximum, all publicly accessible crates, but they can choose on a run-by-run basis. (eg. to efficiently iterate on a proposed language change's effect on known-problem crates identified in a previous run so they can minimize disruption from something allowed by the stability…
-
As far as I can tell (I don't follow Rust development particularly closely, but I have seen the processes unfold across multiple large, and some small PRs), crater runs across ~all crates on crates.io. This is not only used for stable releases, it's often used for running experiments for PRs that may visibly change compiler behavior and cause…
-
Not the author and might be totally wrong but *think* they might have used: 1) `-Z self-profile` [1] compile flag to collect the data 2) crox in the measureme [2] toolkit to convert to a Chrome JSON trace 3) visualized the resulting trace with Perfetto [3] which has support for showing the timeline *and* you can select any region of time of the…
-
> before each stable version of Rust is published, the release team runs a tool called Crater that tests the new version across the public Rust ecosystem Great idea. Haven't heard of any other docs engines actively validating new releases against their ecosystem. The status quo is more along the lines of "we have a release candidate, please try it…
-
This is awesome. Curious on the profiling setup there; flame graphs are something I've been after and haven't found a clear way to get them. I'd love to know how it was done.