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

Better growth factor? #1

Open
ivxvm opened this issue Feb 10, 2022 · 1 comment
Open

Better growth factor? #1

ivxvm opened this issue Feb 10, 2022 · 1 comment

Comments

@ivxvm
Copy link

ivxvm commented Feb 10, 2022

Currently library seems to grow vectors by the factor of 2 when size reaches capacity.
Many languages, including GC based, choose 1.5 or other factors:
https://stackoverflow.com/questions/1100311/what-is-the-ideal-growth-rate-for-a-dynamically-allocated-array
https://sarahnothling.wordpress.com/2015/06/04/optimising-the-growth-factor-of-a-dynamic-array-list/

It's worth investigating, if it makes sense to change the default factor to phi or 1.5 in this context.

PS: Thanks for the library, I really miss this functionality from standard vector!

@ivxvm ivxvm changed the title Better growth factor Better growth factor? Feb 10, 2022
@fumieval
Copy link
Owner

I tried the growth factor of 4181 / 2584 ≒ φ, and it seems to improve the performance slightly so I went ahead with the change.

2
  push/10000: OK (1.41s)
    85.7 μs ± 6.6 μs
golden ratio
  push/10000: OK (1.38s)
    84.1 μs ± 6.7 μs

Thank you for the suggestion!

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