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

Moving `ArrayVec`s has complexity O(capacity()) instead of O(len()) #94

Closed
gnzlbg opened this Issue Feb 6, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@gnzlbg
Copy link
Contributor

gnzlbg commented Feb 6, 2018

The title says it all: moving an ArrayVec has complexity O(capacity()) instead of O(len()). This is pretty bad.

It is trivial to construct examples that show a massive slowdown (100x's slower) with respect to C++'s boost::container::static_vector.

For example, moving an empty ArrayVec<[u64; 512]> involves memcpying 4104 bytes instead of just 8 bytes (the size of len). That's 513x more expensive than C++'s boost::container::static_vector.

@clarfon

This comment has been minimized.

Copy link
Contributor

clarfon commented Feb 6, 2018

I don't see a way of improving this, short of specialising clone_from and suggesting to use that. I'd pose this problem to the Rust upstream repo and not here.

@bluss

This comment has been minimized.

Copy link
Owner

bluss commented Feb 6, 2018

@gnzlbg This seems to be a language-level (Rust) issue, and not arrayvec? As you know, we can't redefine how a value moves.

@bluss

This comment has been minimized.

Copy link
Owner

bluss commented Feb 6, 2018

@bluss

This comment has been minimized.

Copy link
Owner

bluss commented Feb 10, 2018

closed, in Rust we can't change how values of a type move. I would be interested in language-level discussion about what can be done about this.

My suggestion for a workaround is to use a big arrayvec behind a pointer if you need to pass ownership of it around.

@bluss bluss closed this Feb 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.