Skip to content

Provide a better initial size for collections if possible#6464

Merged
dlmarion merged 1 commit into
apache:mainfrom
dlmarion:right-size-collections
Jul 9, 2026
Merged

Provide a better initial size for collections if possible#6464
dlmarion merged 1 commit into
apache:mainfrom
dlmarion:right-size-collections

Conversation

@dlmarion

@dlmarion dlmarion commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@dlmarion dlmarion added this to the 4.0.0 milestone Jul 7, 2026
@dlmarion dlmarion self-assigned this Jul 7, 2026
final Map<String,FileInfo> files;

public Files(Collection<FileInfo> files) {
this.files = new HashMap<>(files.size(), 1.0f);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change from the default 0.75 load factor to 1.0?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the 1.0 load factor prevents resizing until you try to exceed the current size. So this avoids an unnecessary resize as we're filling it up with a known quantity.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. If we know the size before-hand, then we can set the collection size appropriately so that it won't resize.

@dlmarion dlmarion merged commit ff20500 into apache:main Jul 9, 2026
8 checks passed
@dlmarion dlmarion deleted the right-size-collections branch July 9, 2026 12:00
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.

3 participants