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

grow buffer by factor 1.5 #80

Open
frehberg opened this issue Dec 7, 2017 · 2 comments
Open

grow buffer by factor 1.5 #80

frehberg opened this issue Dec 7, 2017 · 2 comments

Comments

@frehberg
Copy link

frehberg commented Dec 7, 2017

Hi, growing the internal buffer of the vector by factor 2 is not ideal, better would be a value close to 1.5

Please read:
https://stackoverflow.com/questions/1100311/what-is-the-ideal-growth-rate-for-a-dynamically-allocated-array

@mbrubeck
Copy link
Collaborator

mbrubeck commented Dec 7, 2017

Yes, we should consider doing this. Some realistic benchmarks would be useful. For some more related discussion, see rust-lang/rust#4961.

The best example I can find of a resizable vector tuned for performance on modern allocators is FBVector. It starts at a minumum of 64 bytes, then grows by factors of 2 up to 4096 bytes, then by factors of 1.5 up to 128 KB, then by factors of 2 for sizes larger than 128 KB. When using jemalloc, it can also tweak allocation sizes based on dynamic information from the allocator. When smallvec adds support for custom allocators (#55) maybe that should include custom growth strategies.

@nnethercote
Copy link
Contributor

I don't buy the argument that 1.5x is better, because "assuming all previous allocations are adjacent" features critically in the argument, and real allocators don't put allocations of varying sizes next to each other. 2x is simple and good.

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