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

Optimize switch sources representation and usage #96838

Merged
merged 2 commits into from
May 10, 2022

Conversation

tmiasko
Copy link
Contributor

@tmiasko tmiasko commented May 8, 2022

  • 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.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 8, 2022
@rust-highfive
Copy link
Collaborator

r? @cjgillot

(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 May 8, 2022
@tmiasko
Copy link
Contributor Author

tmiasko commented May 8, 2022

@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 May 8, 2022
@bors
Copy link
Contributor

bors commented May 8, 2022

⌛ Trying commit 1293d9a22f03f8b5c6c4fd24679b7c06f7cbbdcf with merge 7ffecc61411100715256f3f56f13f5846a4a013b...

@tmiasko tmiasko mentioned this pull request May 8, 2022
@bors
Copy link
Contributor

bors commented May 8, 2022

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

@rust-timer
Copy link
Collaborator

Queued 7ffecc61411100715256f3f56f13f5846a4a013b with parent 8fbd92d, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (7ffecc61411100715256f3f56f13f5846a4a013b): comparison url.

Summary:

  • Primary benchmarks: 🎉 relevant improvements found
  • Secondary benchmarks: 🎉 relevant improvements found
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 0 0 4 6 4
mean2 N/A N/A -0.7% -2.4% -0.7%
max N/A N/A -1.0% -3.0% -1.0%

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
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

Footnotes

  1. number of relevant changes

  2. the arithmetic mean of the percent change

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 8, 2022
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
@tmiasko tmiasko changed the title Avoid constructing switch sources unless strictly necessary Optimize switch sources representation and usage May 8, 2022
@@ -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];
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

@oli-obk
Copy link
Contributor

oli-obk commented May 9, 2022

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented May 9, 2022

📌 Commit 2be012a has been approved by oli-obk

@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 May 9, 2022
@bors
Copy link
Contributor

bors commented May 9, 2022

⌛ Testing commit 2be012a with merge 1eaacc30576db615c0add464c71199f4230008e9...

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
.......... (60/64)
...       (64/64)


/checkout/src/test/rustdoc-gui/search-filter.goml search-filter... FAILED
[ERROR] (line 6) TimeoutError: waiting for selector "#titles" failed: timeout 30000ms exceeded: for command `wait-for: "#titles"`
Build completed unsuccessfully in 0:00:41

@bors
Copy link
Contributor

bors commented May 9, 2022

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 9, 2022
@oli-obk
Copy link
Contributor

oli-obk commented May 9, 2022

@bors retry

@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 May 9, 2022
@bors
Copy link
Contributor

bors commented May 9, 2022

⌛ Testing commit 2be012a with merge cb39073...

@bors
Copy link
Contributor

bors commented May 10, 2022

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing cb39073 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 10, 2022
@bors bors merged commit cb39073 into rust-lang:master May 10, 2022
@rustbot rustbot added this to the 1.62.0 milestone May 10, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (cb39073): comparison url.

Summary:

  • Primary benchmarks: 🎉 relevant improvements found
  • Secondary benchmarks: 🎉 relevant improvements found
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 0 0 4 7 4
mean2 N/A N/A -0.7% -2.0% -0.7%
max N/A N/A -1.0% -2.6% -1.0%

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

@rustbot label: -perf-regression

Footnotes

  1. number of relevant changes

  2. the arithmetic mean of the percent change

@tmiasko tmiasko deleted the lazy-switch-sources branch May 11, 2022 07:19
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. T-compiler Relevant to the compiler 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