-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 large arrays more slowly #11482
Grow large arrays more slowly #11482
Conversation
@mgomes do you want to continue this? Can you add some specs testing the capacity growth? |
@beta-ziliani Thanks for the early review! Sorry I pushed up a draft because I couldn't get the test suite to run locally. If you don't mind waiting a couple more days (it's a holiday here) I'd love to push this one to the finish line. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mgomes !
@@ -52,6 +52,12 @@ class Array(T) | |||
# Size of an Array that we consider small to do linear scans or other optimizations. | |||
private SMALL_ARRAY_SIZE = 16 | |||
|
|||
# The initial capacity reserved for new arrays; just a lucky number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄
Fixes #11445
This introduces the heuristic found in Go for re-sizing arrays. For arrays < 256 elements, the heuristic doubles array capacities as before. For arrays >= 256, it starts to limit the growth of re-sizes. It does so in a linear fashion until around ~20k elements at which it limits array growth to ~25%.
I've included a couple specs showing the progression of the array growth with the new heuristic, but let me know if we should include more progressions. I was just concerned about memory usage.
Progression examples: