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

Move always move the whole SmallVec object. #70

Open
gnzlbg opened this issue Nov 1, 2017 · 7 comments
Open

Move always move the whole SmallVec object. #70

gnzlbg opened this issue Nov 1, 2017 · 7 comments

Comments

@gnzlbg
Copy link

gnzlbg commented Nov 1, 2017

A SmallVec<[f64; 100]> with a capacity() larger than 100 allocates the elements on the heap but moving the SmallVec generates a memcpy over the whole SmallVec object including the unused storage for the 100 f64 elements and not just 3*size.

This seems to be a general problem with enums but I couldn't find a rustc bug to track this, so I don't know if this is intended or even fixable. Anyhow, maybe SmallVec can workaround this behavior somehow?

@emilio
Copy link
Member

emilio commented Nov 2, 2017

I consider this to be a rust bug: rust-lang/rust#42763

@emilio
Copy link
Member

emilio commented Nov 2, 2017

The workaround is "don't move stuff much", unfortunately :(

Thanks a lot for noticing and for the report, but I don't think much can be done from this repo. Please reopen if you think otherwise though.

@emilio emilio closed this as completed Nov 2, 2017
@gnzlbg
Copy link
Author

gnzlbg commented Nov 2, 2017 via email

@emilio
Copy link
Member

emilio commented Nov 2, 2017

Oh ok, I see what you mean, happy to reopen, though still not sure how can this be fixed on our side... Maybe it's better to fix a rust issue (too?).

I don't know how this would be fixed without introducing branches on move, which I don't think it's something you can do.

@emilio emilio reopened this Nov 2, 2017
@Boscop
Copy link

Boscop commented Apr 30, 2021

@emilio Custom move constructors in Rust are possible:
https://mcyoung.xyz/2021/04/26/move-ctors/
This crate uses the approach described in that post:
https://crates.io/crates/moveit

Maybe we could have an optical feature to use this approach for SmallVec?

@emilio
Copy link
Member

emilio commented Apr 30, 2021

Having to wrap all your smallvec declarations in a macro seems like a no-go tbh, specially to fix a relatively minor perf issue.

@KalitaAlexey
Copy link

Is this issue related to my problem?
Using for value in values is always slower for me than for value in &values or for &value in &values.
https://github.com/KalitaAlexey/smallvec_iter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants