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

Eliminate ObligationCauseData #91844

Merged
merged 1 commit into from
Dec 20, 2021

Conversation

nnethercote
Copy link
Contributor

This makes Obligation two words bigger, but avoids allocating a lot of the time.

I previously tried this in #73983 and it didn't help much, but local timings look more promising now.

r? @ghost

@nnethercote
Copy link
Contributor Author

@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 Dec 13, 2021
@bors
Copy link
Contributor

bors commented Dec 13, 2021

⌛ Trying commit ddb96eb0b1587c670438b0e577eb709c90e29447 with merge 220db1ba07e4e16cdbe3889232735221018fe852...

@camelid camelid added I-compiletime Issue: Problems and improvements with respect to compile times. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed I-compiletime Issue: Problems and improvements with respect to compile times. labels Dec 13, 2021
@rust-log-analyzer

This comment has been minimized.

@nnethercote nnethercote force-pushed the rm-ObligationCauseData-2 branch 2 times, most recently from 72588bb to 748ccba Compare December 13, 2021 01:08
@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Dec 13, 2021
@nnethercote
Copy link
Contributor Author

@bors try

@bors
Copy link
Contributor

bors commented Dec 13, 2021

⌛ Trying commit 748ccba835c1336c51462525d136e2314289a284 with merge 498fbcc6241318ce8d97f067af15d4fba425d18b...

@bors
Copy link
Contributor

bors commented Dec 13, 2021

☀️ Try build successful - checks-actions
Build commit: 498fbcc6241318ce8d97f067af15d4fba425d18b (498fbcc6241318ce8d97f067af15d4fba425d18b)

@rust-timer
Copy link
Collaborator

Queued 498fbcc6241318ce8d97f067af15d4fba425d18b with parent f7fd79a, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (498fbcc6241318ce8d97f067af15d4fba425d18b): comparison url.

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

  • Large improvement in instruction counts (up to -3.8% on incr-unchanged builds of deep-vector)
  • Small regression in instruction counts (up to 0.7% on incr-full builds of deeply-nested)

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. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Dec 13, 2021
@nnethercote
Copy link
Contributor Author

Lots more wins than losses among the instruction counts, plus it's a tiny reduction in number of lines of code. I think this is worth going ahead with.

r? @Mark-Simulacrum

@Mark-Simulacrum Mark-Simulacrum added the perf-regression-triaged The performance regression has been triaged. label Dec 14, 2021
@Mark-Simulacrum
Copy link
Member

I agree that these wins exceed the regressions, so this is worth it.

I am wondering, though, if it makes sense to try to go further here. In particular, it seems to me that many ObligationCauseCode's are or could be <= one pointer in "size", in which case Lrc<...> is adding an allocation that's not really necessary.

For example, just by moving the discriminant into the Obligation (one extra byte), we'd be able to represent a lot of the variants inline -- trivially all of the ones that have no data attached, and in theory those which have data that's only usize wide (e.g., a single DefId). I don't off-hand know what the distribution there looks like -- this PR adds a comment suggesting this covers 60% of cases with just MiscObligation, but it's worth noting that we keep adding new obligation cause codes, so presumably that percentage is only going to decrease over time. I'm not sure what the distribution on the rest of the codes is like.

Further optimization seems fine to leave for future PRs, but I would like the comment on the Option discriminant hashing addressed; r=me with that done (another perf run may be in order).

@Mark-Simulacrum Mark-Simulacrum 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 Dec 14, 2021
@camelid camelid removed the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Dec 14, 2021
@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. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 16, 2021
@bors
Copy link
Contributor

bors commented Dec 18, 2021

⌛ Testing commit 47d6bdfd7b00e28839d261f1c7a9de190560079f with merge d985d42bb4d0910b017e761acb7125427ce7aef2...

@bors
Copy link
Contributor

bors commented Dec 18, 2021

💔 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 Dec 18, 2021
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Dec 19, 2021

☔ The latest upstream changes (presumably #92099) made this pull request unmergeable. Please resolve the merge conflicts.

@nnethercote
Copy link
Contributor Author

I rebased to fix the conflict. While there, I added a clean_code() function that trivially avoids some additional allocations relating to the parent_code field, that helps with #87012.

@bors r=Mark-simulacrum

@bors
Copy link
Contributor

bors commented Dec 19, 2021

📌 Commit d7ca962282ccc09fad6c8193fa3a474e339097c5 has been approved by Mark-simulacrum

@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 Dec 19, 2021
@rust-log-analyzer

This comment has been minimized.

This makes `Obligation` two words bigger, but avoids allocating a lot of
the time.

I previously tried this in rust-lang#73983 and it didn't help much, but local
timings look more promising now.
@nnethercote
Copy link
Contributor Author

@bors r=Mark-Simulacrum

@bors
Copy link
Contributor

bors commented Dec 19, 2021

📌 Commit f09b1fa has been approved by Mark-Simulacrum

@bors
Copy link
Contributor

bors commented Dec 20, 2021

⌛ Testing commit f09b1fa with merge ed7a206...

@bors
Copy link
Contributor

bors commented Dec 20, 2021

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing ed7a206 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 20, 2021
@bors bors merged commit ed7a206 into rust-lang:master Dec 20, 2021
@rustbot rustbot added this to the 1.59.0 milestone Dec 20, 2021
@nnethercote nnethercote deleted the rm-ObligationCauseData-2 branch December 20, 2021 04:11
@nnethercote
Copy link
Contributor Author

So we could effectively split ObligationCauseCode in half: one part for all the simple variants, one part for all the complex variants.

I did some quick measurements and the potential for improvement here seems very low. The simple variants account for a small fraction (~5% or less) of the occurrences seen in practice (while compiling std).

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ed7a206): comparison url.

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

  • Small improvement in instruction counts (up to -0.9% on full builds of coercions)
  • Small regression in instruction counts (up to 0.9% on full builds of wg-grammar)

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

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression

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. perf-regression Performance regression. 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