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

Make SmallVector more general-purpose #37371

Closed
nnethercote opened this issue Oct 24, 2016 · 2 comments
Closed

Make SmallVector more general-purpose #37371

nnethercote opened this issue Oct 24, 2016 · 2 comments

Comments

@nnethercote
Copy link
Contributor

SmallVector is a very useful type. It can avoid lots of heap allocations when used on hot paths, which can give nice speed-ups. I have used it in multiple places, and I have more changes in the pipeline that will use it.

But it's not quite as general-purpose as it could be. Ideas for improvement:

  • Rename it as SmallVec, to mirror Vec.
  • Move it from libsyntax to librustc_data_structures.
  • Increase the number of elements that can be present without requiring heap allocation from 1 to 2 or 4. (Because 1 covers a lot of cases, but 2 or 4 would cover more.)
  • Tweak the API to better match Vec. E.g. change zero() to new().
@Mark-Simulacrum
Copy link
Member

I've started some part of this work in implementing a SmallVec8, with a proposed rename to ArrayVec and the accompanying possibly-heap variant AccumulateVec, which should land with #37270, but the ETA on that is not well-defined.

@Ms2ger
Copy link
Contributor

Ms2ger commented Oct 24, 2016

I wonder if there's a way to use the existing rust-smallvec crate yet.

eddyb added a commit to eddyb/rust that referenced this issue Nov 11, 2016
…ddyb

Replace syntax's SmallVector with AccumulateVec

This adds a new type to data_structures, `SmallVec`, which wraps `AccumulateVec` with support for re-allocating onto the heap (`SmallVec::reserve`). `SmallVec` is then used to replace the implementation of `SmallVector` in libsyntax.

r? @eddyb

Fixes rust-lang#37371. Using `SmallVec` instead of libsyntax's `SmallVector` will provide the `N = 2/4` case easily (just needs a few more `Array` impls).

cc @nnethercote, probably interested in this area
eddyb added a commit to eddyb/rust that referenced this issue Nov 12, 2016
…ddyb

Replace syntax's SmallVector with AccumulateVec

This adds a new type to data_structures, `SmallVec`, which wraps `AccumulateVec` with support for re-allocating onto the heap (`SmallVec::reserve`). `SmallVec` is then used to replace the implementation of `SmallVector` in libsyntax.

r? @eddyb

Fixes rust-lang#37371. Using `SmallVec` instead of libsyntax's `SmallVector` will provide the `N = 2/4` case easily (just needs a few more `Array` impls).

cc @nnethercote, probably interested in this area
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