Github Override `clone_from` for some types by a1phyr · Pull Request #85176 · ru...
source link: https://github.com/rust-lang/rust/pull/85176
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.
New issue
Override clone_from
for some types
#85176
Conversation
Override clone_from
method of the Clone
trait for:
cell::RefCell
cmp::Reverse
io::Cursor
mem::ManuallyDrop
This can bring performance improvements.
r? @yaahc
(rust-highfive has picked a reviewer for you, use r? to override)
Awaiting bors try build completion.
@rustbot label: +S-waiting-on-perf
Try build successful - checks-actions
Build commit: ee90cb2 (ee90cb22627d2f2c6828fc4316225d34b4b8bd1a
)
Finished benchmarking try commit (ee90cb2): 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
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.
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 customclone_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).
Commit 9332ac3 has been approved by yaahc
Testing commit 9332ac3 with merge fb84a8750d1f6cd2bdb8a2b96d4fb67a6997616c...
Test failed - checks-actions
Looks like a spurious network error.
@bors retry
@a1phyr: Insufficient privileges: not in try users
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
Testing commit 9332ac3 with merge 3d31363338bc3a4db66237f5be10389cfd01201b...
Test successful - checks-actions
Approved by: yaahc
Pushing 3d31363 to master...
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK