Skip to content

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

Merged
merged 1 commit into from
Apr 4, 2023

Conversation

jsha
Copy link
Contributor

@jsha jsha commented Apr 3, 2023

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.

Fixes #109851

@rustbot
Copy link
Collaborator

rustbot commented Apr 3, 2023

r? @notriddle

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Apr 3, 2023
@@ -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() {
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor Author

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.

@jyn514 jyn514 changed the title rustdoc: uniquify intra-doc links rustdoc: make intra-doc link pass non-quadratic for repeated links Apr 3, 2023
@jyn514 jyn514 added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 3, 2023
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.
@jsha jsha force-pushed the uniquify-intra-doc branch from a755c57 to d9edb05 Compare April 3, 2023 03:46
@rustbot
Copy link
Collaborator

rustbot commented Apr 3, 2023

Some changes occurred in src/librustdoc/clean/types.rs

cc @camelid

@jsha
Copy link
Contributor Author

jsha commented Apr 3, 2023 via email

@rust-timer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Apr 3, 2023

⌛ Trying commit d9edb05 with merge 47695e82e5bfde35d1774a9b7a3ced4eefdb990b...

@bors
Copy link
Collaborator

bors commented Apr 3, 2023

☀️ Try build successful - checks-actions
Build commit: 47695e82e5bfde35d1774a9b7a3ced4eefdb990b (47695e82e5bfde35d1774a9b7a3ced4eefdb990b)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (47695e82e5bfde35d1774a9b7a3ced4eefdb990b): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking 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
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-11.9% [-77.7%, -0.7%] 8
Improvements ✅
(secondary)
-3.7% [-3.7%, -3.7%] 1
All ❌✅ (primary) -11.9% [-77.7%, -0.7%] 8

Max RSS (memory usage)

Results

This 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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.7% [-2.8%, -2.5%] 2
Improvements ✅
(secondary)
-3.9% [-3.9%, -3.9%] 1
All ❌✅ (primary) -2.7% [-2.8%, -2.5%] 2

Cycles

Results

This 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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-15.1% [-64.9%, -1.5%] 5
Improvements ✅
(secondary)
-4.6% [-5.1%, -4.1%] 5
All ❌✅ (primary) -15.1% [-64.9%, -1.5%] 5

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 3, 2023
@notriddle
Copy link
Contributor

notriddle commented Apr 3, 2023

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 3, 2023

📌 Commit d9edb05 has been approved by notriddle

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 3, 2023
@notriddle
Copy link
Contributor

@bors rollup=never

@bors
Copy link
Collaborator

bors commented Apr 4, 2023

⌛ Testing commit d9edb05 with merge eb48e97...

@bors
Copy link
Collaborator

bors commented Apr 4, 2023

☀️ Test successful - checks-actions
Approved by: notriddle
Pushing eb48e97 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 4, 2023
@bors bors merged commit eb48e97 into rust-lang:master Apr 4, 2023
@rustbot rustbot added this to the 1.70.0 milestone Apr 4, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (eb48e97): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-11.8% [-77.7%, -0.6%] 8
Improvements ✅
(secondary)
-3.6% [-3.6%, -3.6%] 1
All ❌✅ (primary) -11.8% [-77.7%, -0.6%] 8

Max RSS (memory usage)

Results

This 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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.1% [3.1%, 3.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.1% [-1.1%, -1.1%] 1
All ❌✅ (primary) - - 0

Cycles

Results

This 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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-23.4% [-64.2%, -2.6%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -23.4% [-64.2%, -2.6%] 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustdoc: intra-doc links on blanket impls cause extra allocations
8 participants