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

SmallVecDeque — small vector optimization for a ring buffer #226

Open
kotauskas opened this issue Jun 22, 2020 · 3 comments
Open

SmallVecDeque — small vector optimization for a ring buffer #226

kotauskas opened this issue Jun 22, 2020 · 3 comments

Comments

@kotauskas
Copy link

Vec and VecDeque are similar in that they both use the same allocation method; they just use the allocation differently. With MaybeUninit<T::Item> and some additional ring buffer management, implementing a SmallVecDeque should be pretty simple.

@ghost
Copy link

ghost commented Aug 23, 2020

I think so. There are often times when we want a deque that only contains 1 or 2 elems for the most time.

@mbrubeck
Copy link
Collaborator

Similar to issue #220, I think I would prefer to see this as a separate crate, built on top of the smallvec crate if appropriate.

@fleabitdev
Copy link

Assuming SmallVecDeque is implemented similarly to VecDeque, I can see a few challenges:

  • At least one element is always unused. For a small inline buffer, this seems wasteful.

  • The buffer length must be a power of two, so SmallVecDeque<usize, 10> would store either eight or sixteen inline elements. It might be better to completely forbid non-power-of-two sizes.

  • The capacity is one less than the buffer length. Either SmallVecDeque<usize, 3> would store four inline elements, or SmallVecDeque<usize, 4> would have an inline capacity of three. Users might unexpectedly upgrade to the next power-of-two buffer size, or unexpectedly spill from inline storage to heap storage.

It might be worth experimenting with an entirely different ring-buffer algorithm for SmallVecDeque, rather than porting VecDeque directly.

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

3 participants