Rustdoc takes 8.5 GB of memory to document stm32h7 #79103
Comments
This is causing docs.rs to have to periodically bump the sandbox limits when documenting stm32 crates: rust-lang/docs.rs#1179. |
P-medium: it's annoying that it takes so much memory, but it's not like you can't document it. And it's being worked on. |
I ran Rustdoc under DHAT and found that a good tenth of the allocations come from rust/src/librustdoc/clean/blanket_impl.rs Line 130 in 2225ee1 |
Another 7% just storing the structs themselves: . Maybe I should be asking just how many impls there are? |
[rustdoc] Calculate span information on demand instead of storing it ahead of time This brings `size_of<clean::types::Span>()` down from over 100 bytes (!!) to only 12, the same as rustc. It brings `Item` down even more, from `784` to `680`. TODO: I need to figure out how to do this for the JSON backend too. That uses `From` impls everywhere, which don't allow passing in the `Session` as an argument. `@P1n3appl3,` `@tmandry,` maybe one of you have ideas? Helps with rust-lang#79103
[rustdoc] Calculate span information on demand instead of storing it ahead of time This brings `size_of<clean::types::Span>()` down from over 100 bytes (!!) to only 12, the same as rustc. It brings `Item` down even more, from `784` to `680`. ~~TODO: I need to figure out how to do this for the JSON backend too. That uses `From` impls everywhere, which don't allow passing in the `Session` as an argument. `@P1n3appl3,` `@tmandry,` maybe one of you have ideas?~~ Figured it out, fortunately only two functions needed to be changed. I like the `convert_x()` format better than `From` everywhere but I'm open to feedback. Helps with rust-lang#79103
[rustdoc] Calculate span information on demand instead of storing it ahead of time This brings `size_of<clean::types::Span>()` down from over 100 bytes (!!) to only 12, the same as rustc. It brings `Item` down even more, from `784` to `680`. ~~TODO: I need to figure out how to do this for the JSON backend too. That uses `From` impls everywhere, which don't allow passing in the `Session` as an argument. `@P1n3appl3,` `@tmandry,` maybe one of you have ideas?~~ Figured it out, fortunately only two functions needed to be changed. I like the `convert_x()` format better than `From` everywhere but I'm open to feedback. Helps with rust-lang#79103
[rustdoc] Box ItemKind to reduce the size of `Item` This brings the size of `Item` from ``` [src/librustdoc/lib.rs:103] std::mem::size_of::<Item>() = 680 ``` to ``` [src/librustdoc/lib.rs:103] std::mem::size_of::<Item>() = 280 ``` This is an alternative to rust-lang#79967; I don't think it makes sense to make both changes. Helps with rust-lang#79103.
[rustdoc] Box `ItemKind::Impl` to shrink the size of Item Helps with rust-lang#79103. Builds on rust-lang#79957 and should not be merged before. Eventually I want to calculate this info on demand (rust-lang#76382) but that turned out to be quite difficult so I'm leaving it for later and slapping on this short-term fix. This brings the size of Item and ItemKind from ``` [src/librustdoc/lib.rs:102] std::mem::size_of::<Item>() = 680 [src/librustdoc/lib.rs:102] std::mem::size_of::<ItemKind>() = 408 ``` to ``` [src/librustdoc/lib.rs:102] std::mem::size_of::<Item>() = 608 [src/librustdoc/lib.rs:102] std::mem::size_of::<ItemKind>() = 336 ``` Waiting to start a perf run until rust-lang#79957 lands.
Get rid of `clean::Deprecation` This brings the size of `item.deprecation` from 56 to 16 bytes. Helps with rust-lang#79103 and rust-lang#76382, in the same vein as rust-lang#79957. r? `@GuillaumeGomez`
[rustdoc] Switch to Symbol for item.name This decreases the size of `Item` from 680 to 616 bytes. It also does a lot less work since it no longer has to copy as much. Helps with rust-lang#79103. r? `@GuillaumeGomez`
Get rid of `clean::Deprecation` This brings the size of `item.deprecation` from 56 to 16 bytes. Helps with rust-lang#79103 and rust-lang#76382, in the same vein as rust-lang#79957. r? `@GuillaumeGomez`
[rustdoc] Switch to Symbol for item.name This decreases the size of `Item` from 680 to 616 bytes. It also does a lot less work since it no longer has to copy as much. Helps with rust-lang#79103. r? `@GuillaumeGomez`
The strange thing that most of the time is not spent on |
Almost all the time in
|
|
Get rid of `clean::Deprecation` This brings the size of `item.deprecation` from 56 to 16 bytes. Helps with rust-lang#79103 and rust-lang#76382, in the same vein as rust-lang#79957. r? `@GuillaumeGomez`
Add more timing info to rustdoc This helped me confirm in rust-lang#79103 (comment) that get_blanket_impls is indeed what's taking all the time on stm32. r? `@Mark-Simulacrum`
[rustdoc] Calculate stability, const_stability, and deprecation on-demand Previously, they would always be calculated ahead of time, which bloated the size of `clean::Item`. Builds on rust-lang#80090 and should not be merged before. Helps with rust-lang#79103 and rust-lang#76382. cc rust-lang#80014 (comment) This brings `Item` down to 568 bytes, down from 616.
Remove `DefPath` from `Visibility` and calculate it on demand Depends on rust-lang#80090 and should not be merged before. Helps with rust-lang#79103 and rust-lang#76382. cc rust-lang#80014 (comment) - `@nnethercote` I figured it out! It was simpler than I expected :) This brings the size of `clean::Visibility` down from 40 bytes to 8. Note that this does *not* remove `clean::Visibility`, even though it's now basically the same as `ty::Visibility`, because the `Invsible` variant means something different from `Inherited` and I thought it would be be confusing to merge the two. See the new comments on `impl Clean for ty::Visibility` for details.
…meGomez [rustdoc] Calculate stability, const_stability, and deprecation on-demand Previously, they would always be calculated ahead of time, which bloated the size of `clean::Item`. Builds on rust-lang#80090 and should not be merged before. Helps with rust-lang#79103 and rust-lang#76382. cc rust-lang#80014 (comment) This brings `Item` down to 568 bytes, down from 616.
…umeGomez Remove `DefPath` from `Visibility` and calculate it on demand Depends on rust-lang#80090 and should not be merged before. Helps with rust-lang#79103 and rust-lang#76382. cc rust-lang#80014 (comment) - `@nnethercote` I figured it out! It was simpler than I expected :) This brings the size of `clean::Visibility` down from 40 bytes to 8. Note that this does *not* remove `clean::Visibility`, even though it's now basically the same as `ty::Visibility`, because the `Invsible` variant means something different from `Inherited` and I thought it would be be confusing to merge the two. See the new comments on `impl Clean for ty::Visibility` for details.
[rustdoc] Box ItemKind to reduce the size of `Item` This brings the size of `Item` from ``` [src/librustdoc/lib.rs:103] std::mem::size_of::<Item>() = 536 ``` to ``` [src/librustdoc/lib.rs:103] std::mem::size_of::<Item>() = 136 ``` This is an alternative to rust-lang#79967; I don't think it makes sense to make both changes. Helps with rust-lang#79103.
Similar to but not the same as #78761: rustdoc uses an inordinate amount of memory to document large crates.
heaptrack_gui
shows almost a third of the memory being allocated inget_blanket_impls
:However, the peak usage is actually in
check_mod_item_types
, which rustdoc can't do much about:Rustdoc should work improving on both the total memory usage and peak memory usage.
This is meant as a tracking issue, since there are issues other than
get_blanket_impls
causing high memory use, such as #76382. There is a Zulip stream for technical discussion.cc @adamgreig
The text was updated successfully, but these errors were encountered: