Skip to content

Conversation

@seberg
Copy link
Member

@seberg seberg commented Oct 6, 2025

Not sure if there is any downsides to this, but I think this is much simpler and pretty much identical.
Plus, I don't quite like that the 1.25 factor could be large, although I admit it seems very unlikely (maybe impossible) to actually trigger a problem there.

EDIT: As a note, I have a similar function that caps overallocation and increments in "neat" values (which double as a minimum overallocation amount). I somewhat assumed that doesn't matter much, but we could definitely do either or both here as well.

if ((arena->cursor + string_storage_size) > newsize) {
// need extra room beyond the expansion factor, leave some padding
newsize = (size_t)(ARENA_EXPAND_FACTOR * (arena->cursor + string_storage_size));
if ((arena->size - arena->cursor) < string_storage_size) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I changed the <= to < here. == seems fine, i.e. at the end size == cursor which should be valid, no?

@ngoldbaum
Copy link
Member

ngoldbaum commented Oct 6, 2025

Thanks for looking at this! Just an FYI I am traveling in Portugal this week and may not have time to look at this until next week.

Not sure if there is any downsides to this, but I think this is much
simpler and pretty much identical.
Plus, I don't quite like that the 1.25 factor could be large, although
I admit it seems very unlikely (maybe impossible) to actually trigger
a problem there.

Signed-off-by: Sebastian Berg <sebastianb@nvidia.com>
@ngoldbaum
Copy link
Member

Thanks for looking at this. I agree that the original code has issues and your fix is fine.

In your edit:

As a note, I have a similar function that caps overallocation and increments in "neat" values (which double as a minimum overallocation amount). I somewhat assumed that doesn't matter much, but we could definitely do either or both here as well.

This seems like a good idea too and I like the idea of having a utility function we can use for growing buffers. If you're up for it, it would be nice to re-use that code here. But also this is fine to merge as-is IMO.

@seberg
Copy link
Member Author

seberg commented Oct 14, 2025

I'll just put this in as back-portable, although dunno if we will. May look into consolidating, but that would make the change unnecessarily bloated for backporting (if it turns out nice).

@seberg seberg added the 09 - Backport-Candidate PRs tagged should be backported label Oct 14, 2025
@seberg seberg merged commit d470611 into numpy:main Oct 14, 2025
77 checks passed
@seberg seberg deleted the string-overalloc branch October 14, 2025 08:35
charris pushed a commit to charris/numpy that referenced this pull request Oct 14, 2025
Not sure if there is any downsides to this, but I think this is much
simpler and pretty much identical.
Plus, I don't quite like that the 1.25 factor could be large, although
I admit it seems very unlikely (maybe impossible) to actually trigger
a problem there.

Signed-off-by: Sebastian Berg <sebastianb@nvidia.com>
charris added a commit that referenced this pull request Oct 14, 2025
MAINT: Simplify string arena growth strategy (#29885)
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants