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

rustdoc: reduce GC work during search #83077

Merged
merged 13 commits into from
Mar 16, 2021

Conversation

notriddle
Copy link
Contributor

No description provided.

There is no reason for this function to return an object,
since it is always used for getting at the name anyhow.
It's used in the inner loop for some popular functions,
so we want to avoid allocating in it.
@rust-highfive
Copy link
Collaborator

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez

@rust-highfive
Copy link
Collaborator

r? @GuillaumeGomez

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 13, 2021
Every time splice() is called, another temporary object is created.
This version, which uses plain objects as a sort of Hash Bag,
should only produce one temporary object each time it's called.
Basically, it doesn't make sense to generate those things every time
you search. That generates a bunch of stuff for the GC to clean up,
when, if the user wanted to do another search, it would just need
to re-do it again.
@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez
Copy link
Member

So overall, you reduce the GC but you instead use more memory (a lot more from what I can see). Not sure how good of a tradeoff this is...

notriddle and others added 2 commits March 13, 2021 09:32
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
@notriddle
Copy link
Contributor Author

So overall, you reduce the GC but you instead use more memory (a lot more from what I can see). Not sure how good of a tradeoff this is...

If it's controversial, I can skip the nameWithoutUnderscores and id changes while keeping the rest of it. None of the other tweaks should increase the memory usage.

@rust-log-analyzer

This comment has been minimized.

@jyn514
Copy link
Member

jyn514 commented Mar 13, 2021

Do you have benchmarks for how much this helps or hurts performance?

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez
Copy link
Member

Having benchmarks (on the std docs because it's big enough to see any impact) would definitely be appreciated here. What we want to check is the performance improvement and the memory usage.

@notriddle
Copy link
Contributor Author

Running this thing in the Web Console does a pretty good job of consistently recording how long a search takes, without having a bunch of other noise dominating the measurements. The new version spend about 634 ms in the GC, and 3,238 ms in the old version.

getSearchInput().focus(); focus = new FocusEvent("focus", {cancelable: true, bubbles: true}); getSearchInput().dispatchEvent(focus); getSearchInput().value = "Vec<AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,AA,BA,CA,DA,EA,FA,GA,HA,IA,JA,KA,LA,>"; focus = new InputEvent("change", {cancelable: true, bubbles: true}); getSearchInput().dispatchEvent(focus); setTimeout(() => {console.profile();document.getElementsByClassName("search-form")[0].onsubmit(focus); setTimeout(console.profileEnd);}, 100);

@GuillaumeGomez
Copy link
Member

That seems very surprising to see such a difference. An important point though: the search-index is loaded when the search input gets the focus, not when you start a search.

Also: can you get the memory diff somehow? That'd be really interesting too.

@notriddle
Copy link
Contributor Author

According to the Firefox memory profiler, these changes raised the memory use from 26MiB to 31MiB.

And, reading through the code again, I found two more tweaks that significantly help with memory consumption:

  • row.id doesn't have any reason to be a string. It's only used for indexing anyhow, so it might as well be a number
  • nameWithoutUndescores doesn't necessarily need to be a fresh allocation, since most names don't have underscores in them

With those two tweaks applied, we're down to 28MiB. Still higher than the original 26, because strings have been raised from 2 -> 3, and objects have been raised from 14 to 15.

@rust-log-analyzer

This comment has been minimized.

This should have negligible effect on time, but it cuts about 1MiB
off of resident memory usage.
There's no reason for it to be a string, since it's only used for
de-duplicating the results arrays anyhow.
@GuillaumeGomez
Copy link
Member

I think the tradeoff is now very acceptable. Thanks a lot for the improvements! I think the CI will fail because you renamed getObjectFromId to getObjectNameFromId. You'll need to update src/tools/rustdoc-js (just grep the old function name) to fix it.

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez
Copy link
Member

Apparently you don't need to update the tool. However, this failure means that the search behavior has been modified.

This basically fixes a search bug introduced by earlier changes.
@notriddle
Copy link
Contributor Author

@GuillaumeGomez

Yep. Turns out I forgot to account for case folding.

@GuillaumeGomez
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Mar 15, 2021

📌 Commit dcba95f has been approved by GuillaumeGomez

@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 Mar 15, 2021
@GuillaumeGomez GuillaumeGomez added A-rustdoc-search Area: Rustdoc's search feature T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Mar 15, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 16, 2021
…, r=GuillaumeGomez

rustdoc: reduce GC work during search
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 16, 2021
Rollup of 10 pull requests

Successful merges:

 - rust-lang#81822 (Added `try_exists()` method to `std::path::Path`)
 - rust-lang#83072 (Update `Vec` docs)
 - rust-lang#83077 (rustdoc: reduce GC work during search)
 - rust-lang#83091 (Constify `copy` related functions)
 - rust-lang#83156 (Fall-back to sans-serif if Arial is not available)
 - rust-lang#83157 (No background for code in portability snippets)
 - rust-lang#83160 (Deprecate RustcEncodable and RustcDecodable.)
 - rust-lang#83162 (Specify *.woff2 files as binary)
 - rust-lang#83172 (More informative diagnotic from `x.py test` attempt atop beta checkout)
 - rust-lang#83196 (Use delay_span_bug instead of panic in layout_scalar_valid_range)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit dbdb2a1 into rust-lang:master Mar 16, 2021
@rustbot rustbot added this to the 1.52.0 milestone Mar 16, 2021
@notriddle notriddle deleted the gc-cleanup-rustdoc-search branch March 16, 2021 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-search Area: Rustdoc's search feature 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.

7 participants