-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Use Iterator::eq and (dogfood) eq_by in compiler and library
#147101
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
Conversation
|
Some changes occurred in compiler/rustc_attr_parsing Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs cc @ZuseZ4 |
|
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
This comment has been minimized.
This comment has been minimized.
085e528 to
049a460
Compare
This comment has been minimized.
This comment has been minimized.
|
r? jdonszelmann |
| /// `self` may contain more segments than the number matched against. | ||
| pub fn starts_with(&self, segments: &[Symbol]) -> bool { | ||
| segments.len() < self.len() && self.segments().zip(segments).all(|(a, b)| a.name == *b) | ||
| segments.len() < self.len() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this really better than what was there before? you still need to take() after the less-than check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure which version I like more, but it's definitely not a clear-cut improvement so I undid this change.
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
049a460 to
f9d10c7
Compare
This comment has been minimized.
This comment has been minimized.
|
@rustbot ready |
|
r=me if you squash the two commits, don't quite see why the 2nd commit is separate from the first |
|
@rustbot author |
f9d10c7 to
68a7c25
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
The separation was just to make reviewing slightly easier :) |
|
@bors r+ rollup |
Rollup of 5 pull requests Successful merges: - #146653 (improve diagnostics for empty attributes) - #146987 (impl Ord for params and use unstable sort) - #147101 (Use `Iterator::eq` and (dogfood) `eq_by` in compiler and library ) - #147123 (Fix removed version numbers of `doc_auto_cfg` and `doc_cfg_hide`) - #147149 (add joboet to library review rotation) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #147101 - yotamofek:pr/iter-eq-and-eq-by, r=jdonszelmann Use `Iterator::eq` and (dogfood) `eq_by` in compiler and library Now that #137122 has landed, we can replace stuff that looks like: ```rust let a: &[T]; let b: &[T]; let eq = a.len() == b.len() && a.iter().zip(b).all(|(a,b)| a == b) ``` with the much simpler `a.iter().eq(b)`, without losing the perf benefit of the different-length-fast-path. Also dogfooded `Iterator::eq_by` (cc #64295 ) while I'm at it. First commit (4d1b6fa) should be very straightforward to review, second one (049a460) is slightly more creative, but IMHO a nice cleanup.
Rollup of 5 pull requests Successful merges: - rust-lang/rust#146653 (improve diagnostics for empty attributes) - rust-lang/rust#146987 (impl Ord for params and use unstable sort) - rust-lang/rust#147101 (Use `Iterator::eq` and (dogfood) `eq_by` in compiler and library ) - rust-lang/rust#147123 (Fix removed version numbers of `doc_auto_cfg` and `doc_cfg_hide`) - rust-lang/rust#147149 (add joboet to library review rotation) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 5 pull requests Successful merges: - rust-lang/rust#146653 (improve diagnostics for empty attributes) - rust-lang/rust#146987 (impl Ord for params and use unstable sort) - rust-lang/rust#147101 (Use `Iterator::eq` and (dogfood) `eq_by` in compiler and library ) - rust-lang/rust#147123 (Fix removed version numbers of `doc_auto_cfg` and `doc_cfg_hide`) - rust-lang/rust#147149 (add joboet to library review rotation) r? `@ghost` `@rustbot` modify labels: rollup
…jdonszelmann Use `Iterator::eq` and (dogfood) `eq_by` in compiler and library Now that rust-lang#137122 has landed, we can replace stuff that looks like: ```rust let a: &[T]; let b: &[T]; let eq = a.len() == b.len() && a.iter().zip(b).all(|(a,b)| a == b) ``` with the much simpler `a.iter().eq(b)`, without losing the perf benefit of the different-length-fast-path. Also dogfooded `Iterator::eq_by` (cc rust-lang#64295 ) while I'm at it. First commit (4d1b6fa) should be very straightforward to review, second one (049a460) is slightly more creative, but IMHO a nice cleanup.
Rollup of 5 pull requests Successful merges: - rust-lang/rust#146653 (improve diagnostics for empty attributes) - rust-lang/rust#146987 (impl Ord for params and use unstable sort) - rust-lang/rust#147101 (Use `Iterator::eq` and (dogfood) `eq_by` in compiler and library ) - rust-lang/rust#147123 (Fix removed version numbers of `doc_auto_cfg` and `doc_cfg_hide`) - rust-lang/rust#147149 (add joboet to library review rotation) r? `@ghost` `@rustbot` modify labels: rollup
…gjubilee In `BTreeMap::eq`, do not compare the elements if the sizes are different. Reverts rust-lang#147101 in library/alloc/src/btree/ rust-lang#147101 replaced some instances of code like `a.len() == b.len() && a.iter().eq(&b)` with just `a.iter().eq(&b)`, but the optimization that PR introduced only applies for `TrustedLen` iterators, and `BTreeMap`'s itertors are not `TrustedLen`, so this theoretically regressed perf for comparing large `BTreeMap`/`BTreeSet`s with unequal lengths but equal prefixes, (and also made it so that comparing two different-length `BTreeMap`/`BTreeSet`s with elements whose `PartialEq` impls that can panic now can panic, though this is not a "promised" behaviour either way (cc rust-lang#149122)) Given that `TrustedLen` is an unsafe trait, I opted to not implement it for `BTreeMap`'s iterators, and instead just revert the change. If someone else wants to audit `BTreeMap`'s iterators to make sure they always return the right number of items (even in the face of incorrect user `Ord` impls) and then implement `TrustedLen` for them so that the optimization works for them, then this can be closed in favor of that (or if the perf regression is deemed too theoretical, this can be closed outright). Example of theoretical perf regression: https://play.rust-lang.org/?version=beta&mode=release&edition=2024&gist=a37e3d61e6bf02669b251315c9a44fe2 (very rough estimates, using `Instant::elapsed`). In release mode on stable the comparison takes ~23.68µs. In release mode on beta/nightly the comparison takes ~48.351057ms.
In `BTreeMap::eq`, do not compare the elements if the sizes are different. Reverts #147101 in library/alloc/src/btree/ #147101 replaced some instances of code like `a.len() == b.len() && a.iter().eq(&b)` with just `a.iter().eq(&b)`, but the optimization that PR introduced only applies for `TrustedLen` iterators, and `BTreeMap`'s itertors are not `TrustedLen`, so this theoretically regressed perf for comparing large `BTreeMap`/`BTreeSet`s with unequal lengths but equal prefixes, (and also made it so that comparing two different-length `BTreeMap`/`BTreeSet`s with elements whose `PartialEq` impls that can panic now can panic, though this is not a "promised" behaviour either way (cc #149122)) Given that `TrustedLen` is an unsafe trait, I opted to not implement it for `BTreeMap`'s iterators, and instead just revert the change. If someone else wants to audit `BTreeMap`'s iterators to make sure they always return the right number of items (even in the face of incorrect user `Ord` impls) and then implement `TrustedLen` for them so that the optimization works for them, then this can be closed in favor of that (or if the perf regression is deemed too theoretical, this can be closed outright). Example of theoretical perf regression: https://play.rust-lang.org/?version=beta&mode=release&edition=2024&gist=a37e3d61e6bf02669b251315c9a44fe2 (very rough estimates, using `Instant::elapsed`). In release mode on stable the comparison takes ~23.68µs. In release mode on beta/nightly the comparison takes ~48.351057ms.
Now that #137122 has landed, we can replace stuff that looks like:
with the much simpler
a.iter().eq(b), without losing the perf benefit of the different-length-fast-path.Also dogfooded
Iterator::eq_by(cc #64295 ) while I'm at it.First commit (4d1b6fa) should be very straightforward to review, second one (049a460) is slightly more creative, but IMHO a nice cleanup.