-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Conversation
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.
Some changes occurred in HTML/CSS/JS. |
(rust-highfive has picked a reviewer for you, use r? to override) |
4627c7c
to
4be594e
Compare
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.
4be594e
to
3f70bfa
Compare
This comment has been minimized.
This comment has been minimized.
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... |
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
If it's controversial, I can skip the |
This comment has been minimized.
This comment has been minimized.
Do you have benchmarks for how much this helps or hurts performance? |
This comment has been minimized.
This comment has been minimized.
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. |
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.
|
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. |
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:
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. |
This comment has been minimized.
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.
2e413b8
to
f57d715
Compare
I think the tradeoff is now very acceptable. Thanks a lot for the improvements! I think the CI will fail because you renamed |
This comment has been minimized.
This comment has been minimized.
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.
Yep. Turns out I forgot to account for case folding. |
@bors: r+ |
📌 Commit dcba95f has been approved by |
…, r=GuillaumeGomez rustdoc: reduce GC work during search
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
No description provided.