Skip to content

stree: Reduce allocations in matchParts #6837

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

Merged
merged 1 commit into from
Apr 28, 2025
Merged

Conversation

neilalexander
Copy link
Member

More often than not, if we need to copy when matching, we're potentially wasting free capacity at the end of the existing parts slice. Instead of allocating a whole new slice, attempt to reuse that capacity. If it overflows into a reallocation then that's not the end of the world, as there should now be more available capacity for the next iteration too.

This is safe to do as in the match function, parts is not modified at any point before the next call to matchParts, therefore unused capacity is not going to be overwritten.

Signed-off-by: Neil Twigg [email protected]

@neilalexander neilalexander marked this pull request as ready for review April 28, 2025 08:59
@neilalexander neilalexander requested a review from a team as a code owner April 28, 2025 08:59
Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

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

LGTM

@neilalexander neilalexander merged commit b89ed24 into main Apr 28, 2025
83 of 88 checks passed
@neilalexander neilalexander deleted the neil/streeparts branch April 28, 2025 14:19
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.

2 participants