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

Box the biggest ast::ItemKind variants #81405

Merged
merged 2 commits into from
Feb 2, 2021
Merged

Box the biggest ast::ItemKind variants #81405

merged 2 commits into from
Feb 2, 2021

Conversation

bugadani
Copy link
Contributor

@bugadani bugadani commented Jan 26, 2021

This PR is a different approach on #81400, aiming to save memory in humongous ASTs.

The three affected item kind enums are:

  • ast::ItemKind (208 -> 112 bytes)
  • ast::AssocItemKind (176 -> 72 bytes)
  • ast::ForeignItemKind (176 -> 72 bytes)

@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(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 Jan 26, 2021
@bugadani bugadani changed the title Box the biggest ast::ItemKind variants [Experiment] Box the biggest ast::ItemKind variants Jan 26, 2021
@Mark-Simulacrum
Copy link
Member

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@bors
Copy link
Contributor

bors commented Jan 26, 2021

⌛ Trying commit 7b379a25a2ac7d8dd3508f73e5cdec3e8a34452d with merge 7fc85fb97c995b5a91e77a8c4addcd865da24d11...

@bors
Copy link
Contributor

bors commented Jan 26, 2021

☀️ Try build successful - checks-actions
Build commit: 7fc85fb97c995b5a91e77a8c4addcd865da24d11 (7fc85fb97c995b5a91e77a8c4addcd865da24d11)

@rust-timer
Copy link
Collaborator

Queued 7fc85fb97c995b5a91e77a8c4addcd865da24d11 with parent 1483e67, future comparison URL.

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

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 26, 2021
@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (7fc85fb97c995b5a91e77a8c4addcd865da24d11): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

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

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 26, 2021
@bugadani
Copy link
Contributor Author

bugadani commented Jan 26, 2021

Wait, what did I do to make typeck faster? I thought that works on the HIR and not the AST o.O Anyway, small runtime improvement and a disappointing lack of improvement in max-rss.

In comparison, a bit less perf gain than #81400, but opposed to that this is at least not completely red on memory.

@Mark-Simulacrum
Copy link
Member

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@bors
Copy link
Contributor

bors commented Jan 27, 2021

⌛ Trying commit ff464fe5d23cee78979bf8669c8c83ef7ffcb2b7 with merge bf1b6dbd7f67fc51be6c4ba42a6d0d25a6fa9a3b...

@bors
Copy link
Contributor

bors commented Jan 27, 2021

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

@rust-timer
Copy link
Collaborator

Queued bf1b6dbd7f67fc51be6c4ba42a6d0d25a6fa9a3b with parent 613ef74, future comparison URL.

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

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 27, 2021
@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (bf1b6dbd7f67fc51be6c4ba42a6d0d25a6fa9a3b): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

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

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 27, 2021
@bugadani
Copy link
Contributor Author

Perf is largely the same as before, max-rss maybe a bit better (uh, less terrible?) if you squint real hard, but that can always be noise.

@bugadani bugadani changed the title [Experiment] Box the biggest ast::ItemKind variants Box the biggest ast::ItemKind variants Jan 29, 2021
@bugadani
Copy link
Contributor Author

I undid most of the clippy formatting changes (thanks, RA), and I declare this ready for review.

@davidtwco davidtwco mentioned this pull request Jan 30, 2021
@bors
Copy link
Contributor

bors commented Jan 31, 2021

☔ The latest upstream changes (presumably #81560) made this pull request unmergeable. Please resolve the merge conflicts.

@cjgillot
Copy link
Contributor

Can you add a static_assert_size! on Item, TraitItem, ImplItem and ForeignItem? This will allow to avoid detect regressions.
Do you have the sizes of those structs before this PR?

}

#[derive(Clone, Encodable, Decodable, Debug)]
pub struct FnKind(pub Defaultness, pub FnSig, pub Generics, pub Option<P<Block>>);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these new structs have named fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly, I'm undecided. These were fine without before, and adding names would just bloat up a lot of match patterns. If we were to start replacing them here, we could go through the whole codebase and replace like two million tuple structs as well.

@bugadani
Copy link
Contributor Author

Can you add a static_assert_size! on Item, TraitItem, ImplItem and ForeignItem?

Sure, but I'm not sure if the structs have the same size on 32bit platforms - wouldn't that be an issue, either now or later?

@cjgillot
Copy link
Contributor

cjgillot commented Jan 31, 2021

Can you add a static_assert_size! on Item, TraitItem, ImplItem and ForeignItem?

Sure, but I'm not sure if the structs have the same size on 32bit platforms - wouldn't that be an issue, either now or later?

They wouldn't be the same. In rustc_hir, those asserts are only enabled on x86_64, and mostly serve as an indication to the reader.

Precision:

#[cfg(target_arch = "x86_64")]
rustc_data_structures::static_assert_size!(hir::Expr<'static>, 72);

@bugadani
Copy link
Contributor Author

bugadani commented Feb 1, 2021

@cjgillot I've added asserts (to the enums, because it's their sizes we want to keep low to avoid wasting memory for the "smaller" variants), and I've updated the PR with the size changes.

There are two more possibilities for the near future, based on this PR:

While gathering the sizes, I've noticed that some of the smaller variants in ItemKind are behind a pointer. I wonder if they are small enough to be inlined into the enum. I'll try that in a followup PR.

Also, #81400 showed that perf-wise there is not much difference between boxing a few variants vs boxing the whole enum. Since this PR aims at saving memory, I'll check if it's worth taking the current approach to the extremes and making ItemKind even smaller. This kind-of conflicts with the previous point, though.

@cjgillot
Copy link
Contributor

cjgillot commented Feb 2, 2021

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Feb 2, 2021

📌 Commit 003fba3 has been approved by cjgillot

@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 Feb 2, 2021
@bors
Copy link
Contributor

bors commented Feb 2, 2021

⌛ Testing commit 003fba3 with merge 3182375...

@bors
Copy link
Contributor

bors commented Feb 2, 2021

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing 3182375 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 2, 2021
@bors bors merged commit 3182375 into rust-lang:master Feb 2, 2021
@rustbot rustbot added this to the 1.51.0 milestone Feb 2, 2021
@bugadani bugadani deleted the ast branch February 2, 2021 20:44
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 3, 2021
Box the biggest ast::ItemKind variants

This PR is a different approach on rust-lang#81400, aiming to save memory in humongous ASTs.

The three affected item kind enums are:
 - `ast::ItemKind` (208 -> 112 bytes)
 - `ast::AssocItemKind` (176 -> 72 bytes)
 - `ast::ForeignItemKind` (176 -> 72 bytes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants