Conversation
|
Implementation looks good to me. Let's confirm the perf gain. Also I'd like @lolbinarycat to have a look as she worked on this recently (iirc). @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
fix quadratic naming of duplicate sidebar links
This comment has been minimized.
This comment has been minimized.
| @@ -0,0 +1,21 @@ | |||
| // Regression test for <https://github.com/rust-lang/rust/issues/158174>. | |||
There was a problem hiding this comment.
I feel like this should be a rustc-perf benchmark, not a regular test, since this is a performance improvement, not a bugfix. @GuillaumeGomez what do you think?
There was a problem hiding this comment.
Why not both? =D
But yes, very good idea!
| struct UsedLinks { | ||
| links: FxHashSet<String>, | ||
| /// Next number to try for each anchor. | ||
| next_suffix: FxHashMap<String, usize>, | ||
| } | ||
|
|
||
| fn get_next_url(used_links: &mut UsedLinks, url: String) -> String { | ||
| if used_links.links.insert(url.clone()) { | ||
| return url; | ||
| } | ||
| let mut add = 1; | ||
| while !used_links.insert(format!("{url}-{add}")) { | ||
| add += 1; | ||
| let add = used_links.next_suffix.entry(url.clone()).or_insert(1); | ||
| loop { | ||
| let candidate = format!("{url}-{add}"); | ||
| *add += 1; | ||
| if used_links.links.insert(candidate.clone()) { | ||
| return candidate; | ||
| } | ||
| } |
There was a problem hiding this comment.
Unless I'm missing an edge case somehow, this should be doable with 1 hashmap and no loop.
| struct UsedLinks { | |
| links: FxHashSet<String>, | |
| /// Next number to try for each anchor. | |
| next_suffix: FxHashMap<String, usize>, | |
| } | |
| fn get_next_url(used_links: &mut UsedLinks, url: String) -> String { | |
| if used_links.links.insert(url.clone()) { | |
| return url; | |
| } | |
| let mut add = 1; | |
| while !used_links.insert(format!("{url}-{add}")) { | |
| add += 1; | |
| let add = used_links.next_suffix.entry(url.clone()).or_insert(1); | |
| loop { | |
| let candidate = format!("{url}-{add}"); | |
| *add += 1; | |
| if used_links.links.insert(candidate.clone()) { | |
| return candidate; | |
| } | |
| } | |
| type UsedLinks = FxHashMap<String, usize>; | |
| fn get_next_url(used_links: &mut UsedLinks, url: String) -> String { | |
| let count = used_links.entry(url.clone()).or_insert(0); | |
| let res = if count == 0 { url } else { format!("{url}-{count}") }; | |
| *count += 1; | |
| res | |
| } |
There was a problem hiding this comment.
Yes, a counter is enough and better indeed . Will make the change with a bit of correctness here ( *count == 0) as in the suggested snippet it compares a &mut usize with a number . Which won't compile . Thank you for the review!
|
Finished benchmarking commit (cc18f18): comparison URL. Overall result: no relevant changes - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countThis perf run didn't have relevant results for this metric. Max RSS (memory usage)Results (primary 3.8%, secondary -3.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -3.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.1%, secondary -0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 498.333s -> 499.277s (0.19%) |
|
Hum... Do we even have a test to stress test the sidebar? Should we add the new sidebar perf test? |
it doesn't seem like it
yes, that would be good, maybe even add a larger test using the python script in the original issue. |
|
If the perf. regression can be shown with a simple crate, I think it would be fine to add it as a stress test benchmark to |
|
Thanks! I'll open a follow-up rustc-perf PR with a stress benchmark based on the script from #158174 . |
|
Please add the new perf test first, like that we can have a more precise view of the impact of this PR (in addition to the numbers you already provided). |
This PR fixes quadratic naming of duplicate sidebar links as discussed in #158174.
Fixes #158174
get_next_urlgives duplicate sidebar links with unique names but it started counting from 1 every time which makes the page quadratic.So to make it more optimal I changed that to remember the next unique number for each name making it linear per page.
Also added the test at
tests/rustdoc-html/deref/sidebar-links-deref-chain.rsResults
r? @GuillaumeGomez