Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Use 1.5x growth factor for LocalVector #100944
base: master
Are you sure you want to change the base?
Use 1.5x growth factor for LocalVector #100944
Changes from all commits
6609caf
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
You can just use
capacity = tight ? p_size : MAX((U)2, capacity + ((1 + capacity) >> 1));
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.
it needs for
if (p_size > capacity) {
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.
This is always true since you already tested this above. If it weren't true after the new capacity was found you'd get memory issues anyway, lol.
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.
No. If we expand from 12 to 13 elements, then this condition will be false because
12 * 1.5 = 18; 12 > 18 == false
.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.
Ah... I'm just now seeing that your implementation is different than I had thought it is.
The previous implementation used to grow to the nearest power of 2 of the requested size.
You implementation grows to 1.5x the previous capacity, and grows tightly to exactly the requested size if this exceeds the 1.5x growth.
I'm not sure which is better, tbh. I can imagine arguments for either implementation. But this is definitely a change of behavior that goes beyond the 1.5x growth factor instead of 2x.
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.
@Nazarwadim This is the one I meant, it definitely warrants discussion before a merge.
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.
So what's wrong with my implementation?
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.
It's a change of behavior, as explained above.
Specifically, your implementation will be slower if
reserve
is called and more elements are added than reserved for, and slightly faster otherwise.This may be a trade-off worth making, but I'm not sure it's appropriate for this PR. If it's possible with a 1.5x growth factor, I would keep it agnostic and use the same behavior as before.