Introduction
As a member of the Rustdoc team, I recently executed a series of pull requests (PRs) that significantly improved Rustdoc's performance, achieving an average wall-time reduction of 25% and up to 40% for certain libraries like hyper and bitmaps. In this article, I will share how I discovered and implemented these performance improvements.
The Initial Bug
It all started with a peculiar bug reported by @theemathas from the Rust release team. During tests of the new beta version with the Crater tool, an issue was found with a crate called indented-blocks. Rustdoc failed with a "reached the configured maximum number of stack frames" error, whereas Rustc successfully compiled the code.
Analysis and Diagnosis
Rustdoc often leverages Rustc APIs to organize and present information. I discovered that Rustdoc was unnecessarily trying to inline documentation for an internal trait in core::fmt, which was not needed for a nearly empty crate. Upon examining the logs, it became clear that Rustdoc was attempting to inline superfluous documentation.
Optimization and Implementation
To tackle this issue, I started by optimizing how Rustdoc handles the inlining of traits. By restricting this feature to necessary elements, we significantly reduced processing time. I also made changes to enhance the caching mechanism, further speeding up the process.
Results
Following these improvements, Rustdoc exhibited a 33% average reduction in processing time, reaching up to 60% on certain microbenchmarks like helloworld. These enhancements not only resolved the initial bug but also provided a better experience for Rustdoc users.
Conclusion
This experience was a lesson in the importance of thorough bug analysis and how a methodical approach can lead to significant improvements. If you're interested in optimizing your tech tools, let's discuss your project in 15 minutes.
Sources
- [Rustdoc Documentation](https://doc.rust-lang.org/rustdoc/)
- [Noah Lev Bartell-Mangel's Blog](https://noahlev.org/blog/2026/08/27/making-rustdoc-faster/)