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

Perf issue: avoid vector copy at each insertion. #2327

Merged
merged 2 commits into from
Mar 20, 2024
Merged

Conversation

greg7mdp
Copy link
Contributor

The vector::reserve(vector::size() + 1) call which is updated in this PR, with typical std::vector implementations, causes the vector to grow by a single element on every reverve, and therefore a memory allocation and full vector copy on every reserve call.

This updates the reserve() call so that the vector capacity grows quadrically.

@greg7mdp greg7mdp requested a review from spoonincode March 20, 2024 11:46
@ericpassmore
Copy link
Contributor

ericpassmore commented Mar 20, 2024

Note:start
group: STABILITY
category: PERFORMANCE
summary: Updates the reserve() call so that the vector capacity grows slower at a quadrically rate.
Note:end

@greg7mdp greg7mdp merged commit 13b1c03 into main Mar 20, 2024
34 checks passed
@greg7mdp greg7mdp deleted the avoid_linear_resize branch March 20, 2024 17:46
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.

4 participants