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(trie): remove some clones #10406

Merged
merged 1 commit into from
Aug 26, 2024
Merged

perf(trie): remove some clones #10406

merged 1 commit into from
Aug 26, 2024

Conversation

DaniPopes
Copy link
Member

@DaniPopes DaniPopes commented Aug 20, 2024

Since extending hashmaps is always a linear operation, we can reduce cloning to only when necessary on a per-field/element basis.

Duplicate some extend fns to take refs to be more efficient than extend(other.clone()).

These show up in profiles under EngineApiTreeHandler -> MemoryOverlayStateProvider::new.

@rkrasiuk
Copy link
Member

nice, will review in am

@mattsse mattsse added the C-perf A change motivated by improving speed, memory usage or disk footprint label Aug 21, 2024
fn extend_inner(&mut self, other: Cow<'_, Self>) {
self.accounts.extend(other.accounts.iter().map(|(&k, &v)| (k, v)));

self.storages.reserve(other.storages.len());
Copy link
Member

Choose a reason for hiding this comment

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

shrink_to_fit after extend?

Copy link
Member Author

Choose a reason for hiding this comment

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

Don't see the point in that if there's gonna be multiple calls to extend

@rkrasiuk rkrasiuk added this pull request to the merge queue Aug 26, 2024
Merged via the queue into main with commit 38087a0 Aug 26, 2024
35 checks passed
@rkrasiuk rkrasiuk deleted the dani/trie-clones branch August 26, 2024 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-perf A change motivated by improving speed, memory usage or disk footprint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants