Skip to content

Conversation

simonvandel
Copy link
Contributor

Avoid n² complexity. This showed up in a profile for match-stress-enum that has 8192 variants

I have only profiled locally against match-stress-enum, so we should have it perf tested to make sure it does not regress other crates.

@rust-highfive
Copy link
Contributor

r? @estebank

(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 Oct 5, 2020
@simonvandel simonvandel changed the title perf: UninhabitedEnumBranching void n^2 perf: UninhabitedEnumBranching avoid n^2 Oct 5, 2020
@estebank
Copy link
Contributor

estebank commented Oct 5, 2020

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Collaborator

bors commented Oct 5, 2020

⌛ Trying commit de89fb67fb8292b1f27f59ea7d585a3e95c9d520 with merge c7115a3597a7b1fbced7d79b8a23e22359edc73d...

@@ -89,7 +91,7 @@ impl<'tcx> MirPass<'tcx> for UninhabitedEnumBranching {
let layout = tcx.layout_of(tcx.param_env(body.source.def_id()).and(discriminant_ty));

let allowed_variants = if let Ok(layout) = layout {
variant_discriminants(&layout, discriminant_ty, tcx)
FxHashSet::from_iter(variant_discriminants(&layout, discriminant_ty, tcx))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
FxHashSet::from_iter(variant_discriminants(&layout, discriminant_ty, tcx))
variant_discriminants(&layout, discriminant_ty, tcx).collect()

..then you can remove the FromIterator import

Copy link
Contributor

Choose a reason for hiding this comment

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

variant_discriminants could be changed to return a FxHashSet directly which would avoid some overhead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in latest commit

@bors
Copy link
Collaborator

bors commented Oct 5, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: c7115a3597a7b1fbced7d79b8a23e22359edc73d (c7115a3597a7b1fbced7d79b8a23e22359edc73d)

@rust-timer
Copy link
Collaborator

Queued c7115a3597a7b1fbced7d79b8a23e22359edc73d with parent a1dfd24, future comparison URL.

@rust-timer
Copy link
Collaborator

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

@simonvandel
Copy link
Contributor Author

simonvandel commented Oct 6, 2020

I interpret the perf results as being good.

This PR should not change behavior, so in a perfect deterministic world I would only expect optimized_mir to be affected by this change. I therefore see all regressions reported in LLVM as noise.

For match-stress-enum this is a clear win. All other benchmarks look neutral.

@jonas-schievink
Copy link
Contributor

r=me with #77597 (comment) addressed

@jonas-schievink jonas-schievink 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 Oct 7, 2020
Avoid n² complexity. This showed up in a profile for match-stress-enum that has 8192 variants
@jonas-schievink
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Oct 7, 2020

📌 Commit e231c47 has been approved by jonas-schievink

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 7, 2020
@bors
Copy link
Collaborator

bors commented Oct 7, 2020

⌛ Testing commit e231c47 with merge e055f87...

@bors
Copy link
Collaborator

bors commented Oct 8, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: jonas-schievink
Pushing e055f87 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 8, 2020
@bors bors merged commit e055f87 into rust-lang:master Oct 8, 2020
@rustbot rustbot added this to the 1.49.0 milestone Oct 8, 2020
@bors bors mentioned this pull request Oct 8, 2020
@Mark-Simulacrum
Copy link
Member

As expected, a minor improvement on the match stress test (https://perf.rust-lang.org/compare.html?start=91a79fb29ac78d057d04dbe86be13d5dcc64309a&end=e055f87cdfcac1f4da6c518a547dee459de0aa26&stat=instructions:u). Slight (0.1%) wins on other benchmarks. Great work!

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.

9 participants