Skip to content

Commit b6e38f8

Browse files
committed
Review comments
- Add PRs targeted at intra-doc link performance - Be more environmentally friendly
1 parent 7cf5c35 commit b6e38f8

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

posts/inside-rust/2021-01-15-rustdoc-performance-improvements.md

+46-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,37 @@ Hi everyone! [**@GuillaumeGomez**] recently tweeted about the rustdoc performanc
1111

1212
The tweet received a lot of comments approving the blog post idea so here we go!
1313

14+
## Performance changes
15+
16+
There were actually only two PRs explicitly meant to improve the performance of rustdoc.
17+
18+
1. Rustdoc: Cache resolved links [#77700](https://github.com/rust-lang/rust/pull/77700)
19+
20+
This does what it says in the title. In particular, this sped up the time to generate intra-doc
21+
links for `stm32h7xx` by a whopping [90000%]. [**@bugadani**](https://github.com/bugadani) did an
22+
excellent job on this, congratulations!
23+
24+
[90000%]: https://github.com/rust-lang/rust/pull/77700#issuecomment-735995025.
25+
26+
2. Don't look for blanket impls in intra-doc links [#79682](https://github.com/rust-lang/rust/pull/77700)
27+
28+
This PR was very disappointing to write. The gist is that if you had
29+
30+
```rust
31+
trait Trait {
32+
fn f() {}
33+
}
34+
35+
impl<T> Trait for T {}
36+
```
37+
38+
then linking to `usize::f` would not only not work, but would take longer to run than the rest of
39+
intra-doc links to run. This temporarily disabled blanket impls until the bug is fixed and the performance can be improved, for a similar [90x] speedup on `stm32h7xx`.
40+
41+
You may be wondering why stm32h7xx was so slow before; see the end of the post for details.
42+
43+
[90x]: https://github.com/rust-lang/rust/pull/79682#issuecomment-738505531
44+
1445
## It's all about cleanup
1546

1647
With the recent growth of the rustdoc team, we finally had some time to pay the technical debt we've been accumulating for a while. To sum it up: removing implementations in rustdoc and use the compiler types directly. First, we need to explain a bit how rustdoc works. When we run it to generate HTML documentation, it goes through several steps:
@@ -24,7 +55,7 @@ With the recent growth of the rustdoc team, we finally had some time to pay the
2455
[**@jyn514**] noticed a while ago that [most of the work in Rustdoc is duplicated](https://github.com/rust-lang/rust/issues/76382): there are actually *three* different abstract syntax trees (ASTs)! One for `doctree`, one for `clean`, and one is the original [HIR](https://rustc-dev-guide.rust-lang.org/hir.html) used by the compiler.
2556
Rustdoc was spending quite a lot of time converting between them. Most of the speed improvements have come from getting rid of parts of the AST altogether.
2657

27-
### Burning down the tree
58+
### Pruning the tree
2859

2960
Most of the work `doctree` did was 100% unnecessary. All the information it had was already present in the [HIR], and recursively walking the crate and building up new types took quite a while to run.
3061

@@ -120,12 +151,25 @@ Most of the existing cleanups have been focused on calculating info on-demand th
120151

121152
### Speed up `collect_blanket_impls`
122153

123-
One of the slowest functions in all of rustdoc is a function called [`get_auto_trait_and_blanket_impls`](https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/clean/utils/fn.get_auto_trait_and_blanket_impls.html). On crates with many blanket implementation, such as `stm32`-generated crates, this can take [almost half of the *total* time](https://github.com/rust-lang/rust/issues/79103#issuecomment-745732064) rustdoc spends on the crate.
154+
One of the slowest functions in all of rustdoc is a function called
155+
[`get_auto_trait_and_blanket_impls`](https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/clean/utils/fn.get_auto_trait_and_blanket_impls.html).
156+
On crates with many blanket implementation, such as `stm32`-generated crates, this can take
157+
[almost half of the *total*
158+
time](https://github.com/rust-lang/rust/issues/79103#issuecomment-745732064) rustdoc spends on
159+
the crate.
124160

125161
We are not sure yet how to speed this up, but there is definitely lots of room for improvement.
162+
If you're interested in working on this, please reach out [on Zulip].
163+
164+
[on Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/247081-t-compiler.2Fperformance/topic/rustdoc.20calls.20.60for_each_relevant_impl.60.20a.20lot
126165

127166
Overall, rustdoc is making rapid progress in performance, but there is still a lot more work to be done.
128167

168+
## Errata
169+
170+
An earlier version of the blog post described the section on slimming `doctree` as "Burning down
171+
the tree". The name was changed to be more environmentally friendly.
172+
129173
[**@jyn514**]: https://github.com/jyn514
130174
[**@GuillaumeGomez**]: https://github.com/GuillaumeGomez
131175
[HIR]: https://rustc-dev-guide.rust-lang.org/hir.html

0 commit comments

Comments
 (0)