Skip to content

Conversation

@duyquang6
Copy link
Contributor

@duyquang6 duyquang6 commented Nov 26, 2025

As discussed #19739 (comment)
Batch write of hashed_state is safe, so I created this PR to cherry-pick old reverted commit

Changes

  • improve extend_sorted_vec use merge (avoid sort at the end) and batch write hashed_state

before

erc20 transfers spam: ~100ms

image

native transfers spam: ~50ms

image

after

erc20 transfers spam: ~80ms

image

native transfers spam: ~30ms

image

@duyquang6 duyquang6 requested a review from joshieDo as a code owner November 26, 2025 13:52
@github-project-automation github-project-automation bot moved this to Backlog in Reth Tracker Nov 26, 2025
@duyquang6 duyquang6 changed the title perf: improve extend_sorted_vec & write batch for hashed_state perf: improve extend_sorted_vec & batch write hashed_state Nov 26, 2025
@mattsse mattsse added C-perf A change motivated by improving speed, memory usage or disk footprint A-db Related to the database labels Nov 27, 2025
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.

pedantic doc nit

@github-project-automation github-project-automation bot moved this from Backlog to In Progress in Reth Tracker Nov 27, 2025
@duyquang6 duyquang6 force-pushed the push-rsnqslrrpszs branch 3 times, most recently from c1ec07c to 40f7bef Compare November 27, 2025 11:36
target.sort_unstable_by(|a, b| a.0.cmp(&b.0));
}
})
.collect();
Copy link
Collaborator

Choose a reason for hiding this comment

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

The previous implementation was specifically designed to avoid having to do a big collect like this; the resulting memory allocation from this collect dwarfs any ostensible speedup you get from not having to sort. I just did a bench comparing your implementation to the previous and this new one is about 2x slower for synthetic datasets:

Image

You can see the bench here if you're curious

Copy link
Contributor Author

@duyquang6 duyquang6 Nov 28, 2025

Choose a reason for hiding this comment

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

very useful bench @mediocregopher
when I first use old version with aggregated hashed state to bench, the result is not good. This is why I think there something wrong with extend_ref or extend_sorted_vec

when I use your bench compare with custom own merge version (not used merge_join_by), it only shine at other target size smaller than other size, but overall case, old version still win. That give me some hint to use this function better, is keep target size and other size similar or larger so might benefit old version

shine case (new better)
image

image

but overall (size similar or target size > other) old still better
image

image

Copy link
Contributor Author

@duyquang6 duyquang6 Nov 28, 2025

Choose a reason for hiding this comment

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

I dump the raw data of HashedPostStateSorted when bench with native-transfer

here is bench result of extend_ref, new version of both is better than in this testcase

image

can double check the bench here - already attach hashed state raw data
Could be raw data might have properties that benchmark doesn’t fully cover 🤔 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-db Related to the database C-perf A change motivated by improving speed, memory usage or disk footprint

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants