-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
bytes: inefficient Buffer.grow algorithm #42984
Comments
Related, for your entertainment: https://commaok.xyz/post/discovering-size-classes/ |
The current implementation of While a growth rate of 1.25x is more memory efficient, it's probably slower due to the increased number of allocations+copying. Switching the growth rate from 2x to 1.25x seems to be a more substantial change than just addressing the wasted space. |
Nevermind, ignore my comment, I just realized an |
Change https://golang.org/cl/349994 mentions this issue: |
According to sizeclasses.go, allocating any amount of space greater than the previous size class and below the current size class is inefficient (e.g., allocating 257B is 11% wasteful since it allocates 288B anyways).
The current
Buffer.grow
algorithm is inefficient since it may choose a buffer size that is in-between size classes, rather than optimally using the entire size class.For example:
While we should avoid teaching
Buffer.grow
about size classes, it could choose values that align with 2n or 2n+2n-1, which would have a high probability of lying exactly on a type-class boundary.The text was updated successfully, but these errors were encountered: