-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Optimize switch sources representation and usage #96838
Conversation
tmiasko
commented
May 8, 2022
•
edited
Loading
edited
- Avoid constructing switch sources unless necessary - switch sources are used by backward analysis with a custom switch int edge effects, but are otherwise unnecessarily computed.
- Use sparse representation of switch sources to avoid quadratic space overhead.
r? @cjgillot (rust-highfive has picked a reviewer for you, use r? to override) |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 1293d9a22f03f8b5c6c4fd24679b7c06f7cbbdcf with merge 7ffecc61411100715256f3f56f13f5846a4a013b... |
☀️ Try build successful - checks-actions |
Queued 7ffecc61411100715256f3f56f13f5846a4a013b with parent 8fbd92d, future comparison URL. |
Finished benchmarking commit (7ffecc61411100715256f3f56f13f5846a4a013b): comparison url. Summary:
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. 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. @bors rollup=never Footnotes |
Switch sources are used by backward analysis with a custom switch int edge effects, but are otherwise unnecessarily computed. Delay the computation until we know that switch sources are indeed required and avoid the computation otherwise.
to avoid quadratic space overhead
1293d9a
to
2be012a
Compare
@@ -322,7 +322,8 @@ where | |||
fn apply(&mut self, mut apply_edge_effect: impl FnMut(&mut D, SwitchIntTarget)) { | |||
assert!(!self.effects_applied); | |||
|
|||
let targets = self.values.iter().map(|&value| SwitchIntTarget { value, target: self.bb }); | |||
let values = &self.body.switch_sources()[self.bb][self.pred]; |
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 don't expect this to affect much, but since we're only interested in self.pred
, it could be cheaper to just look at the terminator of basic block with id self.pred
and iterate over all targets filtering for ones for self.bb
. Caching this map does not seem very useful if "computing" it for specific blocks is just a lookup and an iteration.
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.
Considering that this is the only user of switch_sources
, I'm not sure it is carrying its weight.
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.
According to the discussion on the original pull request #95120, switch sources were introduced to avoid quadratic time complexity associated with the implementation strategy you are just suggesting.
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 guess if we have a switch with lots of targets... 🤷 added to my todo to do some experiments in the future
@bors r+ rollup=never |
📌 Commit 2be012a has been approved by |
⌛ Testing commit 2be012a with merge 1eaacc30576db615c0add464c71199f4230008e9... |
The job Click to see the possible cause of the failure (guessed by this bot)
|
💔 Test failed - checks-actions |
@bors retry |
☀️ Test successful - checks-actions |
Finished benchmarking commit (cb39073): comparison url. Summary:
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression Footnotes |