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

Replace rustc_data_structures::thin_vec::ThinVec with thin_vec::ThinVec #100869

Merged
merged 3 commits into from
Sep 1, 2022

Conversation

nnethercote
Copy link
Contributor

rustc_data_structures::thin_vec::ThinVec looks like this:

pub struct ThinVec<T>(Option<Box<Vec<T>>>);

It's just a zero word if the vector is empty, but requires two
allocations if it is non-empty. So it's only usable in cases where the
vector is empty most of the time.

This commit removes it in favour of thin_vec::ThinVec, which is also
word-sized, but stores the length and capacity in the same allocation as
the elements. It's good in a wider variety of situation, e.g. in enum
variants where the vector is usually/always non-empty.

The commit also:

  • Sorts some Cargo.toml dependency lists, to make additions easier.
  • Sorts some use item lists, to make additions easier.
  • Changes clean_trait_ref_with_bindings to take a
    ThinVec<TypeBinding> rather than a &[TypeBinding], because this
    avoid some unnecessary allocations.

r? @spastorino

@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Aug 22, 2022
@rustbot
Copy link
Collaborator

rustbot commented Aug 22, 2022

Some changes occurred in src/librustdoc/clean/types.rs

cc @camelid

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 22, 2022
@nnethercote
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-log-analyzer

This comment has been minimized.

@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 Aug 22, 2022
@bors
Copy link
Contributor

bors commented Aug 22, 2022

⌛ Trying commit 2c4e3fd9bb4cb00340159b6a3e1b4bfdaff1e22c with merge ffb3c6740056e998519f02c0dbb8072c2341c73f...

@bors
Copy link
Contributor

bors commented Aug 22, 2022

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

@rust-timer
Copy link
Collaborator

Queued ffb3c6740056e998519f02c0dbb8072c2341c73f with parent d0ea1d7, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ffb3c6740056e998519f02c0dbb8072c2341c73f): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

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.

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

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
0.5% [0.2%, 1.0%] 88
Regressions ❌
(secondary)
0.8% [0.2%, 3.1%] 60
Improvements ✅
(primary)
-0.7% [-1.0%, -0.5%] 2
Improvements ✅
(secondary)
-0.8% [-1.0%, -0.4%] 16
All ❌✅ (primary) 0.5% [-1.0%, 1.0%] 90

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.5% [2.0%, 3.1%] 3
Improvements ✅
(primary)
-3.7% [-3.7%, -3.7%] 1
Improvements ✅
(secondary)
-3.3% [-5.0%, -1.0%] 3
All ❌✅ (primary) -3.7% [-3.7%, -3.7%] 1

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
2.3% [1.6%, 3.1%] 5
Regressions ❌
(secondary)
3.1% [2.1%, 4.8%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.3% [1.6%, 3.1%] 5

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Aug 22, 2022
@spastorino
Copy link
Member

@nnethercote I didn't check the code yet, just read your description but ... I was wondering if the perf results were the results you were expecting :). Can you comment on that?.

@nnethercote
Copy link
Contributor Author

Yes, this is disappointing. I'll have to see if I can optimize thin-vec's code.

@Kobzol
Copy link
Contributor

Kobzol commented Aug 22, 2022

I already tried this once in rustdoc with similar results. One annoying thing with these global updates is that it's not easy to see the individual changes. It might very well be that e.g. 80 % of places where ThinVec is used were improved, but the rest regressed so bad that it swayed the total results.

@nnethercote
Copy link
Contributor Author

I already tried this once in rustdoc with similar results.

Is there a PR?

@nnethercote
Copy link
Contributor Author

nnethercote commented Aug 22, 2022

(I already fixed a bug in thin-vec and made some small optimizations.)

@Kobzol
Copy link
Contributor

Kobzol commented Aug 22, 2022

Is there a PR?

Hmm, I found #92514, but that's about thin slices, not thin vecs. I probably didn't even send a PR and just tested it locally, but I remember using the thin_vec crate instead of the rustc ThinVec and not seeing any improvements. But that could have changed since then of course, and I think that I only tested rustdoc.

@nnethercote
Copy link
Contributor Author

Hopefully Gankra/thin-vec#34 will fix most/all of the problems.

@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 Aug 23, 2022
@bors
Copy link
Contributor

bors commented Aug 23, 2022

⌛ Trying commit 745ad84 with merge 5c6507f9a3435a7f5961c0f6e771d5831934d8e4...

@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 Aug 29, 2022
@bors
Copy link
Contributor

bors commented Aug 29, 2022

⌛ Trying commit 78f83f0 with merge ea65f3049b7a96d203ed2fc38f2471bbb0e0cfa5...

@bors
Copy link
Contributor

bors commented Aug 29, 2022

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

@rust-timer
Copy link
Collaborator

Queued ea65f3049b7a96d203ed2fc38f2471bbb0e0cfa5 with parent 94b2b15, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ea65f3049b7a96d203ed2fc38f2471bbb0e0cfa5): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

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.

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

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
0.2% [0.2%, 0.2%] 1
Regressions ❌
(secondary)
0.6% [0.3%, 1.3%] 6
Improvements ✅
(primary)
-0.3% [-0.3%, -0.3%] 1
Improvements ✅
(secondary)
-0.6% [-0.8%, -0.4%] 11
All ❌✅ (primary) -0.0% [-0.3%, 0.2%] 2

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
2.0% [2.0%, 2.0%] 1
Regressions ❌
(secondary)
1.6% [1.6%, 1.6%] 3
Improvements ✅
(primary)
-2.1% [-2.1%, -2.1%] 1
Improvements ✅
(secondary)
-3.4% [-5.3%, -2.5%] 4
All ❌✅ (primary) -0.0% [-2.1%, 2.0%] 2

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.1% [2.1%, 2.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.8% [-3.6%, -2.5%] 5
All ❌✅ (primary) - - 0

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 29, 2022
@nnethercote
Copy link
Contributor Author

@spastorino The improvements now slightly outweigh the regressions. I don't entirely trust the last set of results, because I think there is some noise in these results. But I think it's close enough to performance-neutral to proceed.

@spastorino
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Aug 30, 2022

📌 Commit 78f83f0 has been approved by spastorino

It is now in the queue for this repository.

@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 Aug 30, 2022
@bors
Copy link
Contributor

bors commented Sep 1, 2022

⌛ Testing commit 78f83f0 with merge eac6c33...

@bors
Copy link
Contributor

bors commented Sep 1, 2022

☀️ Test successful - checks-actions
Approved by: spastorino
Pushing eac6c33 to master...

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (eac6c33): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

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
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
0.3% [0.2%, 0.5%] 37
Regressions ❌
(secondary)
0.5% [0.2%, 0.9%] 12
Improvements ✅
(primary)
-0.5% [-0.6%, -0.4%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [-0.6%, 0.5%] 41

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.0% [2.2%, 3.8%] 3
Improvements ✅
(primary)
-1.4% [-1.4%, -1.4%] 1
Improvements ✅
(secondary)
-2.5% [-2.8%, -2.2%] 2
All ❌✅ (primary) -1.4% [-1.4%, -1.4%] 1

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.4% [2.1%, 2.7%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.4% [-3.4%, -3.4%] 1
All ❌✅ (primary) - - 0

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@nnethercote
Copy link
Contributor Author

Ugh, the post-merge perf run looked very different to the pre-merge perf run, despite there being no change to the code. Clearly a lot of noise here, and hard to know which results to trust. I'll see if I can get any follow-up improvements.

@rylev
Copy link
Member

rylev commented Sep 6, 2022

@nnethercote any ideas on follow ups here? The results seem like they're partially noise, but some would appear to be real issues.

@nnethercote
Copy link
Contributor Author

nnethercote commented Sep 7, 2022

Nothing right now, though I have a couple of experiments still to run. But thin_vec::ThinVec is a sufficiently useful tool when it comes to shrinking data structures in general that I'd like to keep it in place regardless. In general, the old rustc_data_structure one was good for cases where the vector is nearly almost always empty (e.g. attributes on expressions) but awful in any other case due to the double allocation. thin_vec has much wider applicability.

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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants