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

Override clone_from for some types #85176

Merged
merged 1 commit into from
May 19, 2021
Merged

Conversation

a1phyr
Copy link
Contributor

@a1phyr a1phyr commented May 11, 2021

Override clone_from method of the Clone trait for:

  • cell::RefCell
  • cmp::Reverse
  • io::Cursor
  • mem::ManuallyDrop

This can bring performance improvements.

@rust-highfive
Copy link
Collaborator

r? @yaahc

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 11, 2021
@Xanewok
Copy link
Member

Xanewok commented May 11, 2021

@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 May 11, 2021
@bors
Copy link
Contributor

bors commented May 11, 2021

⌛ Trying commit 9332ac3 with merge ee90cb22627d2f2c6828fc4316225d34b4b8bd1a...

@bors
Copy link
Contributor

bors commented May 11, 2021

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

@rust-timer
Copy link
Collaborator

Queued ee90cb22627d2f2c6828fc4316225d34b4b8bd1a with parent 5c02926, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (ee90cb22627d2f2c6828fc4316225d34b4b8bd1a): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 12, 2021
@yaahc
Copy link
Member

yaahc commented May 14, 2021

So am I correct in understanding that the changes here don't represent direct optimizations, but instead stop these wrappers from ignoring clone_from impls of inner types, so if the inner type depends heavily on a custom clone_from for performance reasons these wrappers will not be in the way after this change? I was surprised that the perf test didn't show any real improvement on a change that's ostensibly all about improving perf but now I feel like I understand, assuming my assessment is correct.

If that's the case I'd be happy to accept this PR but I think it might be better to try to address this problem in the Clone derive itself, which would have much further reaching impact and would stop us from needing to do these small changes in the future.

@a1phyr
Copy link
Contributor Author

a1phyr commented May 15, 2021

So am I correct in understanding that the changes here don't represent direct optimizations, but instead stop these wrappers from ignoring clone_from impls of inner types, so if the inner type depends heavily on a custom clone_from for performance reasons these wrappers will not be in the way after this change?

Yes, a common example is an io::Cursor<Vec<u8>>. With this PR, usingclone_from avoids allocating a new buffer and dropping the old one.

I was surprised that the perf test didn't show any real improvement on a change that's ostensibly all about improving perf but now I feel like I understand, assuming my assessment is correct.

This optimization is a bit niche, to be fair. I don't think that rustc uses clone_from for these specific types a lot, so I didn't expect this PR to improve compile times. It could really improve some other programs though, and it has a very small cost.

If that's the case I'd be happy to accept this PR but I think it might be better to try to address this problem in the Clone derive itself, which would have much further reaching impact and would stop us from needing to do these small changes in the future.

It was proposed a long time ago (#27939), but it was closed due to the impact on compile times. With this PR, clone_from should be overridden for most of the remaining interesting types (except tuples, looks like I forgot them).

@yaahc
Copy link
Member

yaahc commented May 17, 2021

It was proposed a long time ago (#27939), but it was closed due to the impact on compile times. With this PR, clone_from should be overridden for most of the remaining interesting types (except tuples, looks like I forgot them).

Aah, unfortunate. Thanks for checking the background.

@bors r+

@bors
Copy link
Contributor

bors commented May 17, 2021

📌 Commit 9332ac3 has been approved by yaahc

@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. labels May 17, 2021
@bors
Copy link
Contributor

bors commented May 17, 2021

⌛ Testing commit 9332ac3 with merge fb84a8750d1f6cd2bdb8a2b96d4fb67a6997616c...

@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
* highest error code: E0783
Found 517 error codes
Found 0 error codes with no tests
Done!
thread '<unnamed>' panicked at 'cmd.exec() failed with Error during execution of `cargo metadata`:     Updating git repository `https://github.com/bjorn3/rust-ar.git`
    Updating git submodule `https://github.com/WebAssembly/WASI`
warning: spurious network error (2 tries remaining): failed to connect to github.com: Connection refused; class=Os (2)
warning: spurious network error (1 tries remaining): failed to connect to github.com: Connection refused; class=Os (2)
warning: spurious network error (1 tries remaining): failed to connect to github.com: Connection refused; class=Os (2)
error: failed to get `cranelift-codegen` as a dependency of package `rustc_codegen_cranelift v0.1.0 (/checkout/compiler/rustc_codegen_cranelift)`
Caused by:
  failed to load source for dependency `cranelift-codegen`

Caused by:
Caused by:
  Unable to update https://github.com/bytecodealliance/wasmtime/?branch=main#45bee40f

Caused by:
  failed to update submodule `WASI`

Caused by:
  failed to fetch submodule `WASI` from https://github.com/WebAssembly/WASI
Caused by:
  failed to connect to github.com: Connection refused; class=Os (2)
', src/tools/tidy/src/deps.rs:306:20
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Any', src/tools/tidy/src/main.rs:88:9


command did not execute successfully: "/checkout/obj/build/aarch64-unknown-linux-gnu/stage0-tools-bin/rust-tidy" "/checkout" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage0/bin/cargo" "/checkout/obj/build" "14"


failed to run: /checkout/obj/build/bootstrap/debug/bootstrap --stage 2 test
Build completed unsuccessfully in 0:05:25

@bors
Copy link
Contributor

bors commented May 18, 2021

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 18, 2021
@a1phyr
Copy link
Contributor Author

a1phyr commented May 18, 2021

Looks like a spurious network error.
@bors retry

@bors
Copy link
Contributor

bors commented May 18, 2021

@a1phyr: 🔑 Insufficient privileges: not in try users

@Xanewok
Copy link
Member

Xanewok commented May 18, 2021

warning: spurious network error (2 tries remaining): failed to connect to github.com: Connection refused; class=Os (2)
warning: spurious network error (1 tries remaining): failed to connect to github.com: Connection refused; class=Os (2)
warning: spurious network error (1 tries remaining): failed to connect to github.com: Connection refused; class=Os (2)

@bors retry

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 18, 2021
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label May 18, 2021
@bors
Copy link
Contributor

bors commented May 19, 2021

⌛ Testing commit 9332ac3 with merge 3d31363...

@bors
Copy link
Contributor

bors commented May 19, 2021

☀️ Test successful - checks-actions
Approved by: yaahc
Pushing 3d31363 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 19, 2021
@bors bors merged commit 3d31363 into rust-lang:master May 19, 2021
@rustbot rustbot added this to the 1.54.0 milestone May 19, 2021
bors pushed a commit to rust-lang-ci/rust that referenced this pull request Jun 14, 2021
Forwarding `clone_from` to the inner value changes the observable
behavior, as previously the inner value would *not* be dropped by the
default implementation.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 14, 2021
…one-from, r=m-ou-se

Revert rust-lang#85176 addition of `clone_from` for `ManuallyDrop`

Forwarding `clone_from` to the inner value changes the observable behavior, as previously the inner value would *not* be dropped by the default implementation.

Frankly, this is a super-niche case, so rust-lang#85176 is welcome to argue the behavior should be otherwise! But if we overrride it, IMO documenting the behavior would be good.

Example: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c5d0856686fa850c1d7ee16891014efb
Mark-Simulacrum pushed a commit to Mark-Simulacrum/rust that referenced this pull request Jun 19, 2021
Forwarding `clone_from` to the inner value changes the observable
behavior, as previously the inner value would *not* be dropped by the
default implementation.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 23, 2021
…ulacrum

[beta] Bootstrap from stable

This is the follow up to master/beta promotion, as well as the first round of backports:

* Revert "Allow specifying alignment for functions rust-lang#81234"
* Revert rust-lang#85176 addition of clone_from for ManuallyDrop rust-lang#85758
* rustdoc: revert deref recur to resume inclusion of impl ExtTrait<Local> for ExtType rust-lang#84867
*  [beta] Update cargo rust-lang#86563

r? `@Mark-Simulacrum`
@a1phyr a1phyr deleted the impl_clone_from branch March 12, 2024 17:14
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. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants