

Replace Copy/Clone compiler magic on arrays with library impls by bstrie · Pull...
source link: https://github.com/rust-lang/rust/pull/86041
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
(rust-highfive has picked a reviewer for you, use r? to override)
This comment has been hidden.
The code building the clone shim for array can be removed now as well, right?
The latest upstream changes (presumably #87781) made this pull request unmergeable. Please resolve the merge conflicts.
Hi @bstrie! Would you mind rebasing this PR and resolving the merge conflict so we can do a perf run? Assuming that does not reveal any issues, I think we're about ready to merge this.
This LGTM to me on compiler and traits changes.
Ping from triage:
@bstrie can you please resolve the merge conflicts?
This seems reasonable to me, once the merge conflicts are resolved and a perf run comes back without regressions.
Try build successful - checks-actions
Build commit: 78d6575 (78d657592a19e656b8e8819fea9cb5eca34149f0
)
Finished benchmarking commit (78d6575): comparison url.
Summary: This change led to moderate relevant mixed results in compiler performance.
- Moderate improvement in instruction counts (up to -1.2% on
incr-unchanged
builds ofdeeply-nested
) - Moderate regression in instruction counts (up to 1.4% on
full
builds ofcranelift-codegen
)
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
That looks better...mostly a bit more time spent in LLVM (not completely unexpected). Now this is even a slight improvement in a couple benchmarks.
With the latest results, the balance has shifted away from an intrinsic or some other magic being a good idea, imo.
I think performance results are definitely closer to being acceptable here, I'm OK with not bothering with trying out the shim approach or hand-coding it to generate better IR.
Maybe we could write a simple specialized function for clone
that would be easier for LLVM to optimize on release and would require less codegen on debug (reusing the code for Guard
):
fn clone(&self) -> Self { let mut array = MaybeUninit::uninit_array::<N>(); let mut guard = Guard { array_mut: &mut array, initialized: 0 }; for i in 0..N { let item = src[i].clone(); guard.array_mut[i].write(item); guard.initialized = i; } mem::forget(guard); unsafe { MaybeUninit::array_assume_init(array) } }
Maybe we could write a simple specialized function for
clone
that would be easier for LLVM to optimize on release and would require less codegen on debug (reusing the code forGuard
):
Imo, i think this would better be left as followup.
Okay, given previous review from @joshtriplett, previous discussion during a compiler meeting, and perf review by @Mark-Simulacrum, and my own review of compiler/traits changes, I'm going to go ahead and @bors r+
Commit 61b1394 has been approved by
jackh726
Test failed - checks-actions
@bors retry
Test successful - checks-actions
Approved by: jackh726
Pushing d608229 to master...
Finished benchmarking commit (d608229): comparison url.
Summary: This change led to moderate relevant mixed results in compiler performance.
- Moderate improvement in instruction counts (up to -1.2% on
incr-unchanged
builds ofdeeply-nested
) - Moderate regression in instruction counts (up to 1.0% on
full
builds ofcranelift-codegen
)
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
Recommend
-
29
DataField.js — v0.1.1 Select, sort, filter and perform maths and analysis on your arrays of data Zero-dependency Javascript library for Node and browsers that works with collections
-
99
React hooks: not magic, just arrays Untangling the rules around the proposal using diagrams I am a huge fan of the new hooks API. However, it has some
-
10
Copy link rfcbot commented
-
5
Conversation Copy link Contributor ...
-
14
Copy link Contributor bstrie
-
6
Conversation Copy link Contributor ...
-
6
Brian Robert Callahan Brian Robert Callahan academic, developer, with an eye towards a brighter techno-social life
-
4
Collaborator GustavoARSilva commented
-
3
How the clone command does magic On November 11, 2022 ...
-
6
I'm holding out the for 17-inch version — Lenovo Tab Extreme takes on the iPad Pro, complete with Magic Keyboard clone It's a laptop-sized tablet with a laptop-sized price...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK