-
Notifications
You must be signed in to change notification settings - Fork 13.3k
shared-generics: Do not share instantiations that contain local-only types #138522
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
base: master
Are you sure you want to change the base?
shared-generics: Do not share instantiations that contain local-only types #138522
Conversation
r? @nnethercote rustbot has assigned @nnethercote. Use |
Some changes occurred in compiler/rustc_codegen_ssa |
27302a8
to
5dd1877
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…ibility, r=<try> shared-generics: Do not share instantiations that contain local-only types In Zed shared-generics loading takes up a significant chunk of time in incremental build, as rustc deserializes rmeta of all dependencies of a crate. I've recently realized that shared-generics includes all instantiations of some_generic_function in the following snippet: ```rs pub fn some_generic_function(_: impl Fn()) {} pub fn non_generic_function() { some_generic_function(|| {}); some_generic_function(|| {}); some_generic_function(|| {}); some_generic_function(|| {}); some_generic_function(|| {}); some_generic_function(|| {}); some_generic_function(|| {}); } ``` even though none of these instantiations can actually be created from outside of `non_generic_function`. This is a dummy example, but we do rely on invoking callbacks with FnOnce a lot in our codebase. This PR makes shared-generics account for visibilities of generic arguments; an item is only considered for exporting if it is reachable from the outside or if all of it's arguments are visible outside of the local crate. This PR reduces incremental build time for Zed (touch edito.rs scenario) from 12.4s to 10.4s. I'd love to see a perf run if possible; per my checks this PR does not incur new instantiations in downstream crates, so if there'd be perf regressions, I'd expect them to come from newly-introduced visibility checks.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (7aab6d7): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary -0.4%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary 2.6%, secondary -1.3%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResults (primary 0.8%, secondary -0.1%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 774.645s -> 772.98s (-0.21%) |
huh. that is wild. all over the place. |
I can't tell if the regressions are "directly doing more work in a hot path" or "sharing generics was positively impacting local-only things in some cases, too". |
I wouldn't expect this change to affect linked artifact size (since it should only remove metadata that was redundant in the first place - thus it should not be codegened downstream); my hunch is that it's somehow stripping too many instantiations, which then requires instantiations in downstream crates. I'll take a look later in the day. |
The metadata diff can be seen here. For library crates, the Binary size/Linked artifact size is the size of the |
Thanks for the pointer @Kobzol ! I added dbgs! around upstream_monomorpization (to see when an upstream mono could not be found). In case of exa (which is one of the crates for which we detected instruction count regression) there are new instantiations taking place, so it is indeed the case that this PR changes the set of instantiated functions, which is obviously not right. It should change the size of metadata, but not size of compiled code. |
@osiewicz: what's the status of this PR now? Are you going to make more changes? |
@nnethercote I don't plan to make any more changes, no; I wonder what the result of a perf is after 24932d6 though. As far as I can tell, it removes discrepancies in instantiation sets for cranelift_codegen and exa. Locally it still takes a bit longer to build cranelift_codegen for me though. |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
3ac18cb
to
75e7f42
Compare
@rustbot ready |
75e7f42
to
ba23886
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the overall approach is sound. I do think there are two changes that may improve performance a bit.
1ad087f
to
57eaa9a
Compare
@rustbot ready |
@bors try @rust-timer queue r=me if there is no regression since the last perf run. |
This comment has been minimized.
This comment has been minimized.
…ibility, r=<try> shared-generics: Do not share instantiations that contain local-only types In Zed shared-generics loading takes up a significant chunk of time in incremental build, as rustc deserializes rmeta of all dependencies of a crate. I've recently realized that shared-generics includes all instantiations of some_generic_function in the following snippet: ```rs pub fn some_generic_function(_: impl Fn()) {} pub fn non_generic_function() { some_generic_function(|| {}); some_generic_function(|| {}); some_generic_function(|| {}); some_generic_function(|| {}); some_generic_function(|| {}); some_generic_function(|| {}); some_generic_function(|| {}); } ``` even though none of these instantiations can actually be created from outside of `non_generic_function`. This is a dummy example, but we do rely on invoking callbacks with FnOnce a lot in our codebase. This PR makes shared-generics account for visibilities of generic arguments; an item is only considered for exporting if it is reachable from the outside or if all of it's arguments are visible outside of the local crate. This PR reduces incremental build time for Zed (touch editor.rs scenario) from 12.4s to 10.4s. I'd love to see a perf run if possible; per my checks this PR does not incur new instantiations in downstream crates, so if there'd be perf regressions, I'd expect them to come from newly-introduced visibility checks.
⌛ Trying commit 870bc6a with merge d7249c331c9182e73fc9404ff8b40dbce4593918... |
@bjorn3 FYI there was another perf run in the meantime. |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (d7249c3): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary 0.4%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary -0.3%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResults (primary -0.1%, secondary -0.3%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 761.588s -> 761.224s (-0.05%) |
Perf looks fine. Would you mind squashing your changes? |
…utside of the current crate In Zed shared-generics loading takes up a significant chunk of time in incremental build, as rustc deserializes rmeta of all dependencies of a crate. I've recently realized that shared-generics includes all instantiations of some_generic_function in the following snippet: ```rs pub fn some_generic_function(_: impl Fn()) {} pub fn non_generic_function() { some_generic_function(|| {}); some_generic_function(|| {}); some_generic_function(|| {}); some_generic_function(|| {}); some_generic_function(|| {}); some_generic_function(|| {}); some_generic_function(|| {}); } ``` even though none of these instantiations can actually be created from outside of `non_generic_function`. This PR makes shared-generics account for visibilities of generic arguments; an item is only considered for exporting if it is reachable from the outside or if all of it's arguments are visible outside of the local crate. This PR reduces incremental build time for Zed (touch edito.rs scenario) from 12.4s to 10.4s. Co-authored-by: bjorn3 <[email protected]>
870bc6a
to
b15584b
Compare
In Zed shared-generics loading takes up a significant chunk of time in incremental build, as rustc deserializes rmeta of all dependencies of a crate. I've recently realized that shared-generics includes all instantiations of some_generic_function in the following snippet:
even though none of these instantiations can actually be created from outside of
non_generic_function
. This is a dummy example, but we do rely on invoking callbacks with FnOnce a lot in our codebase.This PR makes shared-generics account for visibilities of generic arguments; an item is only considered for exporting if it is reachable from the outside or if all of it's arguments are visible outside of the local crate.
This PR reduces incremental build time for Zed (touch editor.rs scenario) from 12.4s to 10.4s. I'd love to see a perf run if possible; per my checks this PR does not incur new instantiations in downstream crates, so if there'd be perf regressions, I'd expect them to come from newly-introduced visibility checks.