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

Implement resize!(...; first=true) #57313

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open

Conversation

Tortar
Copy link
Contributor

@Tortar Tortar commented Feb 8, 2025

Fixes #26326

@inkydragon inkydragon added the arrays [a, r, r, a, y, s] label Feb 8, 2025
@nsajko nsajko added the feature Indicates new feature / enhancement requests label Feb 8, 2025
@Tortar
Copy link
Contributor Author

Tortar commented Feb 8, 2025

Actually there is not a lot of consensus on the name in #26326. The options nonetheless could be maybe:

  • resizefirst!(a, n)
  • resize!(a, n, p) where p indicates where the resize! should start at, with 1 as resizefirst!, something similar to @StefanKarpinski comment

the second is also appealing, the first seems better to me because of simmetry with other functions e.g. pushfirst! and popfirst! as @oschulz pointed out. The options are actually also compatible in my opinion.

@LilithHafner LilithHafner added the triage This should be discussed on a triage call label Feb 8, 2025
@LilithHafner
Copy link
Member

IMO this is good functionality to publicize, tagging triage to discuss a new feature and to discuss naming.

@oscardssmith
Copy link
Member

Triage thinks this should be spelled resize(... first=true) (to be consistent with the new sizehint! kwarg in 1.11), but we otherwise like it.

@oscardssmith oscardssmith removed the triage This should be discussed on a triage call label Feb 13, 2025
@Tortar Tortar changed the title Implement resizefirst! Implement resize(..., first=true) Feb 14, 2025
@Tortar Tortar changed the title Implement resize(..., first=true) Implement resize!(..., first=true) Feb 14, 2025
@Tortar
Copy link
Contributor Author

Tortar commented Feb 15, 2025

The failures seem unrelated, let me know if the implementation is okay now

Copy link
Member

@LilithHafner LilithHafner left a comment

Choose a reason for hiding this comment

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

Looks pretty good, I left a few suggestions.

base/bitarray.jl Outdated Show resolved Hide resolved
base/array.jl Show resolved Hide resolved
@LilithHafner LilithHafner changed the title Implement resize!(..., first=true) Implement resize!(...; first=true) Feb 16, 2025
Copy link
Member

@LilithHafner LilithHafner left a comment

Choose a reason for hiding this comment

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

IDK if an optimization that only applies when the resize amount is a multiple of 64 is actually worth implementing, especially if the resulting performance quirk is not documented.

base/bitarray.jl Outdated Show resolved Hide resolved
@Tortar
Copy link
Contributor Author

Tortar commented Feb 16, 2025

IDK if an optimization that only applies when the resize amount is a multiple of 64 is actually worth implementing, especially if the resulting performance quirk is not documented.

to me it seems possibly good because someone interested in such a performance optimization (consider that the optimized version is orders of magnitudes faster than the other) would probably look at the implementation of resize! and try to adapt the code to exploit it

Co-authored-by: Lilith Orion Hafner <[email protected]>
@Tortar
Copy link
Contributor Author

Tortar commented Feb 16, 2025

Also, it seems possible to me to apply this optimization for any n but it requires more global changes (which I'm not sure if they will slowdown other parts of the code though), so this could be the easiest step without perf overhead of that direction

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] feature Indicates new feature / enhancement requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A function to resize vectors in front?
5 participants