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

Introduce sizehint!(s, n; shrink = true) to controll shrinkage #51929

Merged
merged 11 commits into from
Nov 8, 2023

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
base/weakkeydict.jl Outdated Show resolved Hide resolved
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?

base/array.jl Outdated Show resolved Hide resolved
@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
7 checks passed
@vtjnash
Copy link
Member

vtjnash commented Nov 8, 2023

Rebased #51903 on top of this now. Thanks!

@@ -1462,10 +1462,15 @@ For types that support `sizehint!`,
`Base`.

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