-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 size of Clean
types
#92514
Conversation
Some changes occurred in cc @camelid |
r? @ollie27 (rust-highfive has picked a reviewer for you, use r? to override) |
r? rust-lang/rustdoc |
The job Click to see the possible cause of the failure (guessed by this bot)
|
Hmm, it seems that |
☔ The latest upstream changes (presumably #92690) made this pull request unmergeable. Please resolve the merge conflicts. |
r? @camelid |
I'm not sure if it's worth micro-optimizing In terms of the license issue, is it worth doing the perf run given that we won't be able to land this code anyway? If you want, you can also do a perf run locally: https://github.com/rust-lang/rustc-perf/. |
Yeah I did multiple perf. runs locally, I just wanted to check it with PGO, LTO and all the "bells and whistles" on CI :) But anyway, the results weren't stellar, and if the ultimate goal is to remove the clean types, then it's not worth it to complicate it like this. Closing. |
Thanks for trying anyway! ❤️ |
This is an experiment to see how much we could reduce the size of various
clean
types and if it's even worth it. Most of the clean types that contain aVec
do not actually need anyVec
functionality, since theVec
is essentially read only. It could thus be replaced with a boxed slice to reduce its size.The PR is split into three commits:
The first simply replaces most
Vec<T>
s withBox<[T]>
. This reduces the size from24
to16
bytes. Conversion fromBox<[T]>
into aVec
is mostly free, however in the other direction it can be a bit more complex (see next commit).When converting from a vec to a boxed slice, the
into_boxed_slice
method first shrinks theVec
to reduce any excess capacity. I hoped that this shrinking would not happen in rustdoc code and that the capacity would equal the length in most cases, since the vecs are usually built out of avec!
macro or acollect
call. Sadly, this was not the case, and the reallocations from the shrinking outweighed any RSS improvements.To alleviate this, I introduced the
into_boxed_slice2
method, which avoids this shrinking. It is of course a horrible hack, but I didn't know how to do this from outside thevec
module, so this was done just to make it work. This would need to be done in a different way of course if we decide to use this approach.The third commit uses the
thin-slice
crate that offers a thin boxed slice, which further reduces the size from16
to8
bytes. It can hold slices up to length 65535 without an additional indirection.I'm not sure if the RSS improvements will be worth it, but I suppose that it's worth a perf. run.
I suspect that there are many other places in the compiler when a
Vec
could be replaced by a (thin) boxed slice to reduce its size.