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

dont resize in emplace when not necessary #100

Merged
merged 7 commits into from
Dec 17, 2023

Conversation

martinus
Copy link
Owner

Fixes #98. This changes the behavior of unordered_dense:

  • Now an initial map allocates. So creating & never using a bunch of maps will have more overhead - That's not something I optimize for though.
  • operator[], or try_emplace doesn't increase size when the element is found. Basically I had to shift an if to another place, so performance wise there shouldn't be much of a difference. Maybe it's even faster.

…ert occurs

This required a few refactorings. Most importantly, a newly constructed map now allocates
an empty bucket array. This might cause slowdowns when you create lots of maps without
ever inserting anything.

The advantage is that try_emplace should have the same speed, or even be a bit faster; especially
when no insertion happens.
@martinus martinus merged commit 335e66c into main Dec 17, 2023
8 checks passed
@martinus martinus deleted the 2023-12-dont-resize-in-emplace-when-not-necessary branch December 17, 2023 08:00
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.

Race condition when using [] operator on map when accessing a key that is known to already exist
1 participant