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

Improve memory reservation for insert_entry #368

Merged
merged 1 commit into from
Jan 20, 2025

Conversation

cuviper
Copy link
Member

@cuviper cuviper commented Jan 15, 2025

In core::RefMut::insert_unique, used by insert_entry and others, we
were calling reserve_entries before the table insert, which defeats
the goal of matching capacities. We can't directly call that after table
insert though, because we'll be holding an OccupiedEntry that prevents
looking at the table itself. Instead, this code path now uses a more
typical doubling growth on the entries Vec itself, but still enhanced
by considering MAX_ENTRIES_CAPACITY as well.

In `core::RefMut::insert_unique`, used by `insert_entry` and others, we
were calling `reserve_entries` *before* the table insert, which defeats
the goal of matching capacities. We can't directly call that after table
insert though, because we'll be holding an `OccupiedEntry` that prevents
looking at the table itself. Instead, this code path now uses a more
typical doubling growth on the entries `Vec` itself, but still enhanced
by considering `MAX_ENTRIES_CAPACITY` as well.
@cuviper cuviper added this pull request to the merge queue Jan 20, 2025
Merged via the queue into indexmap-rs:master with commit cb520a7 Jan 20, 2025
16 checks passed
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.

1 participant