-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
refactor notable_traits_button
to use iterator combinators instead of for loop
#136816
refactor notable_traits_button
to use iterator combinators instead of for loop
#136816
Conversation
rustbot has assigned @GuillaumeGomez. Use |
(speculating out loud to no one in particular) |
I think it might have an impact on performance, we'll see. I'll run a perf check once suggestion has been applied. I personally tend to prefer |
2f0f308
to
fee4729
Compare
It's a matter of style and personal preference, I guess. I'm the opposite - I usually prefer "functional" style. Especially with stuff like |
Personal taste and stuff. I see improvement, personal taste comes second. 😉 Let's check perf. @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…leanup, r=<try> Refactor `notable_trait_buttons` to use iterator combinators instead of `for` loop Small cleanup. Use `Iterator::any` instead of `for` loop with `predicate = true;`. I think this makes the code more readable... and also has the additional benefit of short-circuiting the iterator when a notable trait is found (a `break` statement was missing in the `for` loop version, I think). Probably won't be significant enough to show on perf results, though.
Oh BTW, if we're talking perf, |
Sounds like a great idea! |
Ok, added another commit with that. |
1c8bb6e
to
6fea3a4
Compare
notable_trait_buttons
to use iterator combinators instead of for
loopnotable_trait_buttons
@GuillaumeGomez |
buf, | ||
r#"<script type="text/json" id="notable-traits-data">{}</script>"#, | ||
write!(buf, r#"<script type="text/json" id="notable-traits-data">{}</script>"#, { | ||
#[allow(rustc::potential_query_instability)] |
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.
This is technically ok, as notable_traits_json
sorts the items, but just looking at this code, that's not clear why.
Given that this is the only callsite, it'd be better to pass a FxHashMap
(instead of an opaque impl Iterator
, so the allow can be next to a comment explaining why it's ok. That way all that reasoning about why this is correct stays local.
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 agree, fixed.
(I used the #[expect]
attribute because it's cool and I hadn't had a chance to use it yet, not sure if it should just be #[allow]
)
6fea3a4
to
afdf48d
Compare
I wonder if it's because you pushed? Well, try not to push before this one runs then. ;) @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…leanup, r=<try> Optimize `notable_trait_buttons` ~Small cleanup. Use `Iterator::any` instead of `for` loop with `predicate = true;`. I think this makes the code more readable... and also has the additional benefit of short-circuiting the iterator when a notable trait is found (a `break` statement was missing in the `for` loop version, I think). Probably won't be significant enough to show on perf results, though.~ Three commits, each attempting to optimize `notable_trait_buttons` by a little bit.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (613e9cd): comparison URL. Overall result: no relevant changes - no action neededBenchmarking 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. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary -0.9%, secondary -0.3%)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.
CyclesResults (primary -14.4%)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.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 787s -> 785.515s (-0.19%) |
afdf48d
to
5ab9abf
Compare
☔ The latest upstream changes (presumably #136828) made this pull request unmergeable. Please resolve the merge conflicts. |
5ab9abf
to
9dd6561
Compare
Woops, wrong button |
Do you think this is worth merging given the perf results? |
I think 0da8b61 is beneficial even with no improvements to perf, it makes the code more readable (IMHO) and a bit more correct (because it short-circuits when it finds a notable trait impl). |
☔ The latest upstream changes (presumably #137425) made this pull request unmergeable. Please resolve the merge conflicts. |
9dd6561
to
9d9bac0
Compare
@aDotInTheVoid rebased and dropped the last two commits, leaving just one which I think is worthwhile (for correctness' sake), even if it doesn't affect perf. LMK if you agree, otherwise I can just close this one for now. |
notable_trait_buttons
notable_traits_button
to use iterator combinators instead of for loop
Yeah, the new version is nicer to read, even if it doesn't give us any more perf. @bors r+ rollup |
…-cleanup, r=aDotInTheVoid refactor `notable_traits_button` to use iterator combinators instead of for loop ~Small cleanup. Use `Iterator::any` instead of `for` loop with `predicate = true;`. I think this makes the code more readable... and also has the additional benefit of short-circuiting the iterator when a notable trait is found (a `break` statement was missing in the `for` loop version, I think). Probably won't be significant enough to show on perf results, though.~ Three commits, each attempting to optimize `notable_trait_buttons` by a little bit.
Rollup of 7 pull requests Successful merges: - rust-lang#136293 (document capacity for ZST as example) - rust-lang#136355 (Add `*_value` methods to proc_macro lib) - rust-lang#136359 (doc all differences of ptr:copy(_nonoverlapping) with memcpy and memmove) - rust-lang#136816 (refactor `notable_traits_button` to use iterator combinators instead of for loop) - rust-lang#138363 (Add `From<{integer}>` for `f16`/`f128` impls) - rust-lang#138552 (Misc print request handling cleanups + a centralized test for print request stability gating) - rust-lang#138573 (Make `_Unwind_Action` a type alias, not enum) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 5 pull requests Successful merges: - rust-lang#136293 (document capacity for ZST as example) - rust-lang#136359 (doc all differences of ptr:copy(_nonoverlapping) with memcpy and memmove) - rust-lang#136816 (refactor `notable_traits_button` to use iterator combinators instead of for loop) - rust-lang#138552 (Misc print request handling cleanups + a centralized test for print request stability gating) - rust-lang#138573 (Make `_Unwind_Action` a type alias, not enum) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#136816 - yotamofek:pr/notable-traits-button-cleanup, r=aDotInTheVoid refactor `notable_traits_button` to use iterator combinators instead of for loop ~Small cleanup. Use `Iterator::any` instead of `for` loop with `predicate = true;`. I think this makes the code more readable... and also has the additional benefit of short-circuiting the iterator when a notable trait is found (a `break` statement was missing in the `for` loop version, I think). Probably won't be significant enough to show on perf results, though.~ Three commits, each attempting to optimize `notable_trait_buttons` by a little bit.
Small cleanup.Use
Iterator::any
instead offor
loop withpredicate = true;
.I think this makes the code more readable... and also has the additional benefit of short-circuiting the iterator when a notable trait is found (a
break
statement was missing in thefor
loop version, I think). Probably won't be significant enough to show on perf results, though.Three commits, each attempting to optimize
notable_trait_buttons
by a little bit.