-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Vec::clone_from
is slow
#28601
Comments
Replacing the implementation of
fixes this for me, and |
That makes clone_from shallow and not recursive. I can totally see zip causing problems. Maybe some zip optimizations can help? |
I guess we should keep the reuse of the current values, might be faster for types that need to be dropped because the length can be kept fixed instead of shrinking first and regrowing later. Just replace the zip with a faster loop. |
The best non-shallow clone I've managed is
Comparing it to |
Using |
@apasel422 My suggestion prior is giving me better times. Yours:
Mine:
Clone:
And, for what it's worth,
I'm not sure why the discrepancy, especially for |
@Veedrac Hmm. The call to |
In the process of implementing #28481 for
BinaryHeap
, I noticed thatVec::clone_from
is often slower thanVec::clone
:Output with
rustc 1.5.0-nightly (b2f379cdc 2015-09-23)
:These benchmarks are probably naive (and different sizes may have a more meaningful effect), but it seems to warrant investigation.
The text was updated successfully, but these errors were encountered: