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

Populate correct initial capacity for List/Set/Map/ImmutableList.Builder #1468

Merged
merged 1 commit into from
Jun 16, 2023

Conversation

snazy
Copy link
Contributor

@snazy snazy commented Jun 7, 2023

  • Uses the new ArrayList(int) constructor when size is available
  • Fixes the initial capacity calculation considering the default load factor of .75 for sets + maps
  • Uses ImmutableList.builderWithExpectedSize where appropriate

This change avoids a bunch of "resize" operations and some unnecessary object allocations / heap pressure.

* Uses the `new ArrayList(int)` constructor when `size` is available
* Fixes the initial capacity calculation considering the default load factor of `.75` for sets + maps
* Uses `ImmutableList.builderWithExpectedSize` where appropriate

This change avoids a bunch of "resize" operations and some unnecessary object allocations / heap pressure.
@elucash
Copy link
Member

elucash commented Jun 8, 2023

Thank you for the PR! it looks good, I just need another detailed look before merge

@snazy
Copy link
Contributor Author

snazy commented Jun 16, 2023

@elucash You ok with the PR.
Would love to have this change being released, because that really brings a huge win, especially when pre-populated collections are passed to an immutable's of function.

@elucash
Copy link
Member

elucash commented Jun 16, 2023

Thank you for remainder. I did have another look and it ok, merging it

@elucash elucash merged commit 28ba97e into immutables:master Jun 16, 2023
16 checks passed
@snazy snazy deleted the properly-size-list-set-map branch October 9, 2023 07:17
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

Successfully merging this pull request may close these issues.

None yet

2 participants