The Wayback Machine - https://web.archive.org/web/20210902171937/https://github.com/rust-lang/rust/pull/88522
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: Box GenericArgs::Parenthesized.output #88522

Merged
merged 2 commits into from Sep 2, 2021

Conversation

@camelid
Copy link
Member

@camelid camelid commented Aug 31, 2021

Split out from #88379.

This reduces the size of GenericArgs from 104 bytes to 56 bytes,
essentially reducing it by half.

GenericArgs is one of the fields of PathSegment, so this should
reduce the amount of memory allocated for PathSegments in the cases
where the generics are not for a Fn, FnMut, or FnOnce trait.

r? @jyn514

@camelid
Copy link
Member Author

@camelid camelid commented Aug 31, 2021

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

@rust-timer rust-timer commented Aug 31, 2021

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@bors
Copy link
Contributor

@bors bors commented Aug 31, 2021

Trying commit 074d79f with merge 51d7bb9...

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 31, 2021
Box `GenericArgs::Parenthesized.output`

Split out from rust-lang#88379.

This reduces the size of `GenericArgs` from 104 bytes to 56 bytes,
essentially reducing it by half.

`GenericArgs` is one of the fields of `PathSegment`, so this should
reduce the amount of memory allocated for `PathSegment`s in the cases
where the generics are not for a `Fn`, `FnMut`, or `FnOnce` trait.

r? `@jyn514`
@bors
Copy link
Contributor

@bors bors commented Aug 31, 2021

☀️ Try build successful - checks-actions
Build commit: 51d7bb9 (51d7bb9752da9a4aa758f2dab28c1b56245687ed)

@rust-timer
Copy link
Collaborator

@rust-timer rust-timer commented Aug 31, 2021

Queued 51d7bb9 with parent 6f388bb, future comparison URL.

@rust-timer
Copy link
Collaborator

@rust-timer rust-timer commented Aug 31, 2021

Finished benchmarking try commit (51d7bb9): comparison url.

Summary: This benchmark run did not return any relevant changes.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

@camelid
Copy link
Member Author

@camelid camelid commented Aug 31, 2021

max-rss looks to have improved by between 0.8% and 1.6% for several benchmarks, with no significant regressions. instruction count is unchanged.

@jyn514
jyn514 approved these changes Sep 1, 2021
Copy link
Member

@jyn514 jyn514 left a comment

The rustc_assert_size is the only change I feel strongly about, the rest you can choose to add or not. Good catch! I wouldn't have found this :)

src/librustdoc/clean/auto_trait.rs Outdated Show resolved Hide resolved
output: if output != Type::Tuple(Vec::new()) { Some(output) } else { None },
}
let output =
if output != Type::Tuple(Vec::new()) { Some(Box::new(output)) } else { None };

This comment has been minimized.

@jyn514

jyn514 Sep 1, 2021
Member

Personally I would use box output here 🤷 but it won't affect performance in practice, output is already on the stack.

Oh, this is the bit that breaks #83718 (comment) ! I've been looking for it.

This comment has been minimized.

@camelid

camelid Sep 1, 2021
Author Member

Personally I would use box output here 🤷

Yeah, I thought about that, but someone recently removed all the uses of box_syntax from rustdoc and other tools; I think the goal is to get rid of box_syntax eventually. IIRC from the discussion there, the newest version of LLVM has an optimization that gets rid of the perf difference, but I may be misremembering.

This comment has been minimized.

@camelid

camelid Sep 1, 2021
Author Member

Oh, this is the bit that breaks #83718 (comment) ! I've been looking for it.

Hooray! 🎉

src/librustdoc/json/conversions.rs Show resolved Hide resolved
src/librustdoc/clean/types.rs Show resolved Hide resolved
@jyn514 jyn514 changed the title Box GenericArgs::Parenthesized.output rustdoc: Box GenericArgs::Parenthesized.output Sep 1, 2021
@camelid camelid force-pushed the camelid:box-paren-output branch from 074d79f to 3a0b073 Sep 1, 2021
@jyn514
jyn514 approved these changes Sep 1, 2021
Copy link
Member

@jyn514 jyn514 left a comment

r=me unless you want to try boxing GenericArgs

#[derive(Clone, PartialEq, Eq, Debug, Hash)]
crate struct PathSegment {
crate name: Symbol,
crate args: GenericArgs,
}

// `PathSegment` occurs multiple times in every `Path`, so its size can
// significantly affect rustdoc's memory usage.
rustc_data_structures::static_assert_size!(PathSegment, 64);

Comment on lines 2028 to 2039

This comment has been minimized.

@jyn514

jyn514 Sep 1, 2021
Member

Hmm, this is a good point - I wonder whether it hurts or helps to box GenericArgs instead of output? Are you interested in making another perf run with that change? (no problem if not, this is still a good perf improvement as-is)

This comment has been minimized.

@camelid

camelid Sep 1, 2021
Author Member

Huh, I just saw your comment now; I wonder if there was a glitch in GitHub.

The thing is that GenericArgs is constructed for every PathSegment, so I think rustdoc would still be allocating the same amount of memory as without the Box (in fact, a bit more, because of the usize for the Box). Whereas with the change I made, the Box is only constructed if (a) the GenericArgs is for Fn sugar and (b) the Fn sugar has an output type.

However, making PathSegment.args an Option<Box<GenericArgs>> that would be None if there were no GenericArgs (the common case) could give us a nice perf win. One problem with that is that we would then have multiple ways to represent no GenericArgs.

This comment has been minimized.

@camelid

camelid Sep 1, 2021
Author Member

Actually, writing up that comment just gave me an idea for another way to improve perf :D

Here it is: #88574

@camelid camelid force-pushed the camelid:box-paren-output branch from 3a0b073 to c3ceee1 Sep 1, 2021
@rust-log-analyzer

This comment has been hidden.

camelid added 2 commits Aug 23, 2021
This reduces the size of `GenericArgs` from 104 bytes to 56 bytes,
essentially reducing it by half.

`GenericArgs` is one of the fields of `PathSegment`, so this should
reduce the amount of memory allocated for `PathSegment`s in the cases
where the generics are not for a `Fn`, `FnMut`, or `FnOnce` trait.

I also added `static_assert_size!`s to `GenericArgs` and `PathSegment`
to ensure they don't increase in size unexpectedly.
@jyn514
Copy link
Member

@jyn514 jyn514 commented Sep 1, 2021

@bors r+

@bors
Copy link
Contributor

@bors bors commented Sep 1, 2021

📌 Commit 280e167 has been approved by jyn514

@bors
Copy link
Contributor

@bors bors commented Sep 2, 2021

Testing commit 280e167 with merge e3c71f1...

@bors
Copy link
Contributor

@bors bors commented Sep 2, 2021

☀️ Test successful - checks-actions
Approved by: jyn514
Pushing e3c71f1 to master...

@bors bors merged commit e3c71f1 into rust-lang:master Sep 2, 2021
11 checks passed
11 checks passed
@github-actions
PR (mingw-check, ubuntu-latest-xl)
Details
@github-actions
PR (x86_64-gnu-llvm-10, ubuntu-latest-xl)
Details
@github-actions
PR (x86_64-gnu-tools, 1, ubuntu-latest-xl)
Details
@github-actions
auto
Details
@github-actions
master
Details
@github-actions
bors build finished
Details
@github-actions
bors build finished
Details
@github-actions
bors build finished
Details
@github-actions
bors build finished
Details
@bors
homu Test successful
Details
@camelid camelid deleted the camelid:box-paren-output branch Sep 2, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 2, 2021
rustdoc: Box `GenericArg::Const` to reduce enum size

This is blocked on rust-lang#88522 and should be rebased over it once merged before perf is run.

r? `@ghost`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants