3

Replace `rustc_data_structures::thin_vec::ThinVec` with `thin_vec::ThinVec` by n...

 1 year ago
source link: https://github.com/rust-lang/rust/pull/100869
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Conversation

Contributor

@nnethercote nnethercote commented 17 days ago

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

All reactions

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

17 days ago

Collaborator

rustbot commented 17 days ago

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

cc @camelid

rust-highfive

added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label

17 days ago

Contributor

Author

nnethercote commented 17 days ago

This comment has been minimized.

Contributor

Author

nnethercote commented 17 days ago

Collaborator

rust-timer commented 17 days ago

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

rustbot

added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label

17 days ago

Contributor

bors commented 17 days ago

hourglass Trying commit 2c4e3fd with merge ffb3c67...

Contributor

bors commented 17 days ago

sunny Try build successful - checks-actions
Build commit: ffb3c67 (ffb3c6740056e998519f02c0dbb8072c2341c73f)

Collaborator

rust-timer commented 17 days ago

Collaborator

rust-timer commented 17 days ago

Finished benchmarking commit (ffb3c67): comparison URL.

Overall result: xwhite_check_mark 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 x
(primary)
0.5% [0.2%, 1.0%] 88
Regressions x
(secondary)
0.8% [0.2%, 3.1%] 60
Improvements white_check_mark
(primary)
-0.7% [-1.0%, -0.5%] 2
Improvements white_check_mark
(secondary)
-0.8% [-1.0%, -0.4%] 16
All xwhite_check_mark (primary) 0.5% [-1.0%, 1.0%] 90

Max RSS (memory usage)

Results

Cycles

Results

Footnotes

  1. the arithmetic mean of the percent change

  2. number of relevant changes

rustbot

added perf-regression Performance regressions

and removed S-waiting-on-perf Status: Waiting on a perf run to be completed.

labels

17 days ago

Member

spastorino commented 17 days ago

@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?.

Contributor

Author

nnethercote commented 17 days ago

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

Contributor

Kobzol commented 17 days ago

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.

Contributor

Author

nnethercote commented 17 days ago

I already tried this once in rustdoc with similar results.

Is there a PR?

Contributor

Author

nnethercote commented 17 days ago

edited

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

Kobzol reacted with thumbs up emoji All reactions

Contributor

Kobzol commented 17 days ago

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.

Contributor

Author

nnethercote commented 16 days ago

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

Contributor

Author

nnethercote commented 16 days ago

Collaborator

rust-timer commented 16 days ago

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

rustbot

added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label

16 days ago

Contributor

bors commented 16 days ago

hourglass Trying commit 745ad84 with merge 5c6507f...

Contributor

Author

nnethercote commented 10 days ago

Collaborator

rust-timer commented 10 days ago

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

rustbot

added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label

10 days ago

Contributor

bors commented 10 days ago

hourglass Trying commit 78f83f0 with merge ea65f30...

Contributor

bors commented 10 days ago

sunny Try build successful - checks-actions
Build commit: ea65f30 (ea65f3049b7a96d203ed2fc38f2471bbb0e0cfa5)

Collaborator

rust-timer commented 10 days ago

Collaborator

rust-timer commented 10 days ago

Finished benchmarking commit (ea65f30): comparison URL.

Overall result: xwhite_check_mark 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 x
(primary)
0.2% [0.2%, 0.2%] 1
Regressions x
(secondary)
0.6% [0.3%, 1.3%] 6
Improvements white_check_mark
(primary)
-0.3% [-0.3%, -0.3%] 1
Improvements white_check_mark
(secondary)
-0.6% [-0.8%, -0.4%] 11
All xwhite_check_mark (primary) -0.0% [-0.3%, 0.2%] 2

Max RSS (memory usage)

Results

Cycles

Results

Footnotes

  1. the arithmetic mean of the percent change

  2. number of relevant changes

rustbot

removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label

10 days ago

Contributor

Author

nnethercote commented 10 days ago

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

Member

spastorino commented 10 days ago

@bors r+

Contributor

bors commented 10 days ago

pushpin Commit 78f83f0 has been approved by spastorino

It is now in the queue for this repository.

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

10 days ago

Contributor

bors commented 7 days ago

hourglass Testing commit 78f83f0 with merge eac6c33...

Contributor

bors commented 7 days ago

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

Collaborator

rust-timer commented 7 days ago

Finished benchmarking commit (eac6c33): comparison URL.

Overall result: x 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 x
(primary)
0.3% [0.2%, 0.5%] 37
Regressions x
(secondary)
0.5% [0.2%, 0.9%] 12
Improvements white_check_mark
(primary)
-0.5% [-0.6%, -0.4%] 4
Improvements white_check_mark
(secondary)
- - 0
All xwhite_check_mark (primary) 0.2% [-0.6%, 0.5%] 41

Max RSS (memory usage)

Results

Cycles

Results

Footnotes

  1. the arithmetic mean of the percent change

  2. number of relevant changes

fbstj reacted with eyes emoji All reactions

Contributor

Author

nnethercote commented 7 days ago

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.

spastorino reacted with thumbs up emoji All reactions

Contributor

rylev commented 2 days ago

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

Contributor

Author

nnethercote commented 2 days ago

edited

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

Reviewers

No reviews

Labels
merged-by-bors This PR was explicitly merged by bors perf-regression Performance regressions 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

Milestone

1.65.0

Development

Successfully merging this pull request may close these issues.

None yet

9 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK