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 camelid added I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. I-compiletime Issue: Problems and improvements with respect to compile times. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Aug 31, 2021
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 31, 2021
@camelid
Copy link
Member Author

camelid commented Aug 31, 2021

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

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

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 31, 2021
@bors
Copy link
Contributor

bors commented Aug 31, 2021

⌛ Trying commit 074d79f0e66ed08d6bf514523314a6e27f6a48f0 with merge 51d7bb9752da9a4aa758f2dab28c1b56245687ed...

@bors
Copy link
Contributor

bors commented Aug 31, 2021

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

@rust-timer
Copy link
Collaborator

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

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (51d7bb9752da9a4aa758f2dab28c1b56245687ed): 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

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 31, 2021
@jyn514 jyn514 removed the I-compiletime Issue: Problems and improvements with respect to compile times. label Aug 31, 2021
@camelid
Copy link
Member Author

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.

Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 1, 2021
@jyn514 jyn514 changed the title Box GenericArgs::Parenthesized.output rustdoc: Box GenericArgs::Parenthesized.output Sep 1, 2021
@camelid camelid added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 1, 2021
Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me unless you want to try boxing GenericArgs

Comment on lines 2028 to 2039
#[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);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Member Author

@camelid camelid Sep 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

@camelid camelid Sep 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Here it is: #88574

@jyn514 jyn514 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 1, 2021
@camelid camelid added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 1, 2021
@rust-log-analyzer

This comment has been minimized.

@jyn514 jyn514 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 1, 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.
@camelid camelid added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 1, 2021
@jyn514
Copy link
Member

jyn514 commented Sep 1, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Sep 1, 2021

📌 Commit 280e167 has been approved by jyn514

@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 Sep 1, 2021
@bors
Copy link
Contributor

bors commented Sep 2, 2021

⌛ Testing commit 280e167 with merge e3c71f1...

@bors
Copy link
Contributor

bors commented Sep 2, 2021

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 2, 2021
@bors bors merged commit e3c71f1 into rust-lang:master Sep 2, 2021
@camelid camelid deleted the box-paren-output branch September 2, 2021 02:40
@cuviper cuviper added this to the 1.56.0 milestone Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. merged-by-bors This PR was explicitly merged by bors. 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.

8 participants