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): avoid (de)allocating an extra prefix set #13020

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

hai-rise
Copy link
Contributor

@hai-rise hai-rise commented Nov 29, 2024

Previously we created StorageRoot with a PrefixSet::Default only to replace it immediately with with_prefix_set. This extra (de)allocation is not cheap as it has an Arc and is in the hot path of processing each leaf account node. We profiled live root calculation for new blocks with 10k-50k of account changes and StateRoot::calculate spent 1-2% of its time deallocating this extra prefix set. It is more expensive than RLP-encoding the accounts and ~25x more than #13004.

image

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

cool, ty

this lgtm, reasonable to add the default::default as parameter

pending @rkrasiuk

#[cfg(feature = "metrics")] metrics: TrieRootMetrics,
) -> Self {
Self {
trie_cursor_factory,
hashed_cursor_factory,
hashed_address,
prefix_set: PrefixSet::default(),
prefix_set,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, yeah this makes sense

@mattsse mattsse added the C-perf A change motivated by improving speed, memory usage or disk footprint label Nov 29, 2024
@mattsse mattsse added this pull request to the merge queue Dec 5, 2024
Merged via the queue into paradigmxyz:main with commit da03b79 Dec 5, 2024
41 checks passed
@hai-rise hai-rise deleted the avoid-extra-alloc branch December 5, 2024 14:05
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