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

SmallVec<[u8; 16]>::clone is not optimized to a memcpy #260

Open
saethlin opened this issue Mar 22, 2021 · 3 comments
Open

SmallVec<[u8; 16]>::clone is not optimized to a memcpy #260

saethlin opened this issue Mar 22, 2021 · 3 comments

Comments

@saethlin
Copy link
Contributor

Playground example: https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=64230bf4215b7206e80b1f37198cf611

When I'm cloning a small SmallVec I don't mind this at all, but there should probably be a branch for the spilled case.


I'm not amazing at reading assembly but I think it's actually worse than "not a memcpy", pretty sure I see the increment for the SetLenOnDrop in there still 😬

@mbrubeck
Copy link
Collaborator

Note: You can work around this for now by enabling the nightly-only "specialization" feature, or by replacing buf.clone() with:

SmallVec::from_slice(buf)

@saethlin
Copy link
Contributor Author

Interesting. So would it be better to implement Clone using SmallVec::from_slice?

@mbrubeck
Copy link
Collaborator

That's what the specialization feature does. Without specialization, that's hard to do because from_slice (and memcpy) only works for T: Copy, while clone works for any T: Clone.

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

2 participants