Skip to content

Conversation

@petvana
Copy link
Member

@petvana petvana commented Oct 29, 2023

This is a second part of #51629 to introduce shrink = true argument for sizehint! into public API. Fell free to propose a different name, or way to control shrinkage.

Thinks to do:

  • Implement for Vector
  • Implement for Set
  • Tests for Vector
  • Tests for Set
  • News and compat

@petvana petvana added collections Data structures holding multiple items, e.g. sets triage This should be discussed on a triage call labels Oct 29, 2023
@vtjnash
Copy link
Member

vtjnash commented Oct 30, 2023

LGTM. Thanks for working on this.

@vtjnash vtjnash removed the triage This should be discussed on a triage call label Oct 30, 2023
petvana and others added 2 commits October 31, 2023 18:32
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

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

What does this need to promote it from draft?

@petvana petvana marked this pull request as ready for review November 3, 2023 09:22
@petvana
Copy link
Member Author

petvana commented Nov 4, 2023

Are CI problems related? I'll update branch to test.

@petvana
Copy link
Member Author

petvana commented Nov 4, 2023

CI passes and PR seems ready.

@vtjnash vtjnash merged commit 9f2f3ce into JuliaLang:master Nov 8, 2023
@vtjnash
Copy link
Member

vtjnash commented Nov 8, 2023

Rebased #51903 on top of this now. Thanks!

3. `empty!` is nearly costless (and O(1)) for types that support this kind of preallocation.
4. `shrink` controls if the collection can be shrunk.
Copy link
Member

Choose a reason for hiding this comment

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

Reading this, I don't understand what the argument does. Would you mind adding a more detailed explanation? Also it would seem more appropriate to mention the argument above, outside of the "# Notes on the performance model", as I wouldn't expect to have to read a performance section to find out the meaning of an argument.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, this seems like a fair point. The new optional argument enables us to suggest not to shrink the already reserved capacity when suggesting new size by setting shrink = false. This is helpful for algorithms like merging two collection where you want to pre-allocate memory, but there is not reason to change (shrink) size if all the data fits. I'm not a native speaker, would you be able to propose a more fitting description?

Copy link
Member

Choose a reason for hiding this comment

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

I've not a native speaker either, but see #52226. I hope I got it right.

nalimilan added a commit that referenced this pull request Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

collections Data structures holding multiple items, e.g. sets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants