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

Do not reallocate on sizehint to same size #49703

Merged
merged 1 commit into from
May 9, 2023

Conversation

jakobnissen
Copy link
Member

The sizehint! code currently do not reallocate when sizehinting to a smaller size if 1/8th or fewer elements will be freed. However, the check rounds down, so an array of size e.g. 3 resized to size 3 will "free" 1/8th of the elements, namely zero elements, needlessly resizing.
This commit changes the check to only reallocate if MORE than 1/8th of elements will be freed.

Close #49695

The sizehint! code currently do not reallocate when sizehinting to a smaller
size if 1/8th or fewer elements will be freed. However, the check rounds down,
so an array of size e.g. 3 resized to size 3 will "free" 1/8th of the elements,
namely zero elements, needlessly resizing.
This commit changes the check to only reallocate if MORE than 1/8th of elements
will be freed.
@oscardssmith oscardssmith added performance Must go faster arrays [a, r, r, a, y, s] labels May 9, 2023
@KristofferC KristofferC added the merge me PR is reviewed. Merge when all tests are passing label May 9, 2023
@JeffBezanson JeffBezanson merged commit d10d90c into JuliaLang:master May 9, 2023
@oscardssmith oscardssmith removed the merge me PR is reviewed. Merge when all tests are passing label May 9, 2023
@jakobnissen jakobnissen deleted the sizehint branch May 10, 2023 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sizehint! may allocate when not necessary
4 participants