-
Notifications
You must be signed in to change notification settings - Fork 13.4k
rustdoc: make intra-doc link pass non-quadratic for repeated links #109876
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
Conversation
r? @notriddle (rustbot has picked a reviewer for you, use r? to override) |
@@ -918,7 +918,10 @@ impl LinkCollector<'_, '_> { | |||
for md_link in preprocessed_markdown_links(&doc) { | |||
let link = self.resolve_link(item, item_id, module_id, &doc, &md_link); | |||
if let Some(link) = link { | |||
self.cx.cache.intra_doc_links.entry(item.item_id).or_default().push(link); | |||
let entry = self.cx.cache.intra_doc_links.entry(item.item_id).or_default(); | |||
if entry.iter().find(|other| **other == link).is_none() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the issue, it seems like this still means we're going to iterate over all the entries -- maybe this should be a FxHashSet or so, instead of a vec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, when I try this, tests/rustdoc/intra-doc/prim-precedence.rs starts failing. I haven't quite dug in yet but I suspect it's for a good reason - I think the precedence of primitive links may be relying on an ordering property of the Vec?
In any case if you want to look at the modified commit with FxHashSet it's here: https://github.com/rust-lang/rust/compare/master...jsha:rust:uniquify-intra-doc-link-2?expand=1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swapping FxHashSet out for FxIndexSet there seems to make tests pass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, perfect! Thanks for the tip.
In the collect_intra_doc_links pass, links to a given item that occurred repeatedly were getting inserted into a Vec<clean::ItemLink> repeatedly. This led to n^2 behavior (where n = the number of pages generated), particularly for the intra-doc link on the `Into<U> for T where U: From<T>` blanket implementation, since that link appears on every single struct page.
Some changes occurred in src/librustdoc/clean/types.rs cc @camelid |
@bors try @rust-timer queue
|
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit d9edb05 with merge 47695e82e5bfde35d1774a9b7a3ced4eefdb990b... |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (47695e82e5bfde35d1774a9b7a3ced4eefdb990b): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
|
@bors r+ |
@bors rollup=never |
☀️ Test successful - checks-actions |
Finished benchmarking commit (eb48e97): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
|
In the collect_intra_doc_links pass, links to a given item that occurred repeatedly were getting inserted into a
Vec<clean::ItemLink>
repeatedly. This led to n^2 behavior (where n = the number of pages generated), particularly for the intra-doc link on theInto<U> for T where U: From<T>
blanket implementation, since that link appears on every single struct page.Fixes #109851