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 impl Hash for ObligationCauseData by not hashing ObligationCauseCode variant fields #90996

Merged
merged 1 commit into from
Nov 19, 2021

Conversation

the8472
Copy link
Member

@the8472 the8472 commented Nov 18, 2021

Split out from #90913 since it's a clear performance win and should be easier to review.

It speeds up hashing for Obligation deduplication by only hashing the discriminant of the ObligationCauseCode enum instead of its contents. That shouldn't affect hash quality much since there are several other fields in Obligation which should be unique enough, especially the predicate itself which is hashed as an interned pointer.

selection deduplicates obligations through a hashset at some point, computing the hashes for ObligationCauseCode
appears to dominate the hashing cost. bodyid + span + discriminant hash hopefully will sufficiently unique
unique enough.
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 18, 2021
@the8472 the8472 added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Nov 18, 2021
@matthewjasper
Copy link
Contributor

@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 Nov 18, 2021
@bors
Copy link
Contributor

bors commented Nov 18, 2021

⌛ Trying commit 78b5f2d with merge 4d6fdfcc90813f646820764dbf3cc985d883d9af...

@bors
Copy link
Contributor

bors commented Nov 18, 2021

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

@rust-timer
Copy link
Collaborator

Queued 4d6fdfcc90813f646820764dbf3cc985d883d9af with parent 6414e0b, future comparison URL.

@the8472
Copy link
Member Author

the8472 commented Nov 18, 2021

Huh, this shouldn't need another perf run, I already linked one for this commit in my opening comment.

Split out from #90913 since it's a clear performance win

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (4d6fdfcc90813f646820764dbf3cc985d883d9af): comparison url.

Summary: This change led to very large relevant mixed results 🤷 in compiler performance.

  • Very large improvement in instruction counts (up to -58.2% on full builds of diesel)
  • Moderate regression in instruction counts (up to 1.0% on incr-unchanged builds of wg-grammar)

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 led to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

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

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Nov 18, 2021
@the8472
Copy link
Member Author

the8472 commented Nov 18, 2021

The wg-grammar change probably is noise since it didn't show up in the previous perf run on the same commit changes. incr-unchanged runs are quite sensitive to the 1/32-randomized incremental cache verification.

@matthewjasper
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Nov 18, 2021

📌 Commit 78b5f2d has been approved by matthewjasper

@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 Nov 18, 2021
@camelid
Copy link
Member

camelid commented Nov 18, 2021

Should this be marked as relnotes-perf? Documenting diesel was sped up by 58%! (cc @rust-lang/rustdoc)

@Mark-Simulacrum Mark-Simulacrum added the relnotes-perf Performance improvements that should be mentioned in the release notes. label Nov 18, 2021
@GuillaumeGomez
Copy link
Member

Sounds like it is definitely worth mentioning it indeed!

@bors
Copy link
Contributor

bors commented Nov 19, 2021

⌛ Testing commit 78b5f2d with merge 18fa434...

@bors
Copy link
Contributor

bors commented Nov 19, 2021

☀️ Test successful - checks-actions
Approved by: matthewjasper
Pushing 18fa434 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 19, 2021
@bors bors merged commit 18fa434 into rust-lang:master Nov 19, 2021
@rustbot rustbot added this to the 1.58.0 milestone Nov 19, 2021
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (18fa434): comparison url.

Summary: This change led to very large relevant improvements 🎉 in compiler performance.

  • Very large improvement in instruction counts (up to -58.1% on full builds of diesel)

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

@rustbot label: -perf-regression

@rustbot rustbot removed the perf-regression Performance regression. label Nov 19, 2021
@@ -123,6 +124,14 @@ pub struct ObligationCauseData<'tcx> {
pub code: ObligationCauseCode<'tcx>,
}

impl Hash for ObligationCauseData<'_> {
Copy link
Contributor

Choose a reason for hiding this comment

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

For next time: I suggest leaving a brief comment explaining why this custom hash is used, because it's non-obvious and no fun to have to dig through version control history to understand why.

Copy link
Member

Choose a reason for hiding this comment

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

Please open an issue so it's not forgotten.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not opposed to adding comments but

no fun to have to dig through version control history

seems a bit subjective, for me that's 3 clicks which is hardly onerous. So that didn't quite meet my threshold of adding a comment.

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. relnotes-perf Performance improvements that should be mentioned in the release notes. 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.

10 participants