Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Almost half the time rustdoc spends on stm32h7xx-hal is in intra-doc links #78761

Closed
jyn514 opened this issue Nov 5, 2020 · 8 comments · Fixed by #79682
Closed

Almost half the time rustdoc spends on stm32h7xx-hal is in intra-doc links #78761

jyn514 opened this issue Nov 5, 2020 · 8 comments · Fixed by #79682
Assignees
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-traits Area: Trait system E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. I-compiletime Issue: Problems and improvements with respect to compile times. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@jyn514
Copy link
Member

jyn514 commented Nov 5, 2020

$ cargo rustdoc --features=stm32h742 -- -Z time-passes
time: 45.092; rss: 2537MB	collect-intra-doc-links
    Finished dev [unoptimized + debuginfo] target(s) in 1m 59s

rustdoc --version:

rustdoc 1.49.0-nightly (ffa2e7ae8 2020-10-24)

cc stm32-rs/stm32-rs#3

@jyn514 jyn514 added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. I-compiletime Issue: Problems and improvements with respect to compile times. A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name labels Nov 5, 2020
@jyn514
Copy link
Member Author

jyn514 commented Nov 5, 2020

-Z self-profile

+-------------------------------------------------+-----------+-----------------+----------+------------+
| Item                                            | Self time | % of total time | Time     | Item count |
+-------------------------------------------------+-----------+-----------------+----------+------------+
| collect-intra-doc-links                         | 45.67s    | 52.971          | 45.68s   | 1          |
+-------------------------------------------------+-----------+-----------------+----------+------------+
| render_html                                     | 17.25s    | 20.008          | 17.25s   | 1          |
+-------------------------------------------------+-----------+-----------------+----------+------------+
| collect-trait-impls                             | 12.71s    | 14.740          | 17.87s   | 1          |
+-------------------------------------------------+-----------+-----------------+----------+------------+
| <unknown>                                       | 5.36s     | 6.221           | 7.20s    | 2122524    |
+-------------------------------------------------+-----------+-----------------+----------+------------+
| clean_crate                                     | 1.61s     | 1.873           | 2.21s    | 1          |
+-------------------------------------------------+-----------+-----------------+----------+------------+
Total cpu time: 86.209807708s

@jyn514
Copy link
Member Author

jyn514 commented Nov 5, 2020

Nearly 100% of that time is spent in get_blanket_impls.

blanket-impls

Is this even required for intra-doc links? AFAIK this is only for Send and Sync, which don't have associated items.

@jyn514
Copy link
Member Author

jyn514 commented Nov 5, 2020

... why is InferCtxtInner::new taking a quarter of the time?

@jyn514 jyn514 added the A-traits Area: Trait system label Nov 5, 2020
@jyn514
Copy link
Member Author

jyn514 commented Nov 5, 2020

I think this could be sped up quite a bit by only considering traits that have an associated item of the right name. Then rustdoc wouldn't have to go through the trait system at all, just look at it long enough to see it wouldn't work even if it did apply to the type.

@jyn514
Copy link
Member Author

jyn514 commented Nov 5, 2020

Relevant code:

let implicit_impls = crate::clean::get_auto_trait_and_blanket_impls(cx, ty, did);

pub fn get_blanket_impls(&self, ty: Ty<'tcx>, param_env_def_id: DefId) -> Vec<Item> {

We could change get_blanket_impls to take a filter parameter, that wouldn't be too invasive I think.

@jyn514 jyn514 added E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Nov 5, 2020
@est31
Copy link
Member

est31 commented Nov 5, 2020

It probably also doesn't help that for_each_relevant_impl simplifies the type to an extent where all generic args are erased and then iterates on all trait implementations of it:

if let Some(impls) = impls.non_blanket_impls.get(&simp) {

If you have gazillions of impl Trait for F<A1> {} .... impl Trait for F<A10000> then that's a problem :)

Reducing the number of traits this (rather expensive) search is done is a good idea!

@est31
Copy link
Member

est31 commented Nov 5, 2020

I think the strategy similar to #78317 (comment) would be helpful here too, but I guess the lower hanging fruit (checking whether the trait contains the name in the first place) should be tried before.

@seeplusplus
Copy link

Discussed in Discord with @jyn514 , I'll be trying my hand at this one 🚀
@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-traits Area: Trait system E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. I-compiletime Issue: Problems and improvements with respect to compile times. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants