bnb-chain / reth

BSC and opBNB client based on the Reth fork
Apache License 2.0
72 stars 19 forks source link

feat: add trie prefetch when executing blocks #56

Closed keefel closed 2 months ago

keefel commented 4 months ago

Description

This pull request enhances merkleization efficiency by prefetching trie nodes from the database during execution.

Rationale

This pull request can enhance merkleization efficiency by approximately 56% for the BSC network.

Example

We separately tracked the time taken for inserting blocks, executing blocks, and calculating the state root during live sync. We will compare these metrics to gain insights into their performance.

BSC Test Result - Live sync 14K blocks, from 41550000 to 41564139.

The Prefetch feature boosts state root calculation efficiency during BSC live sync without compromising block execution efficiency. This leads to a 56% decrease in state root calculation time and a 29% reduction in total block insertion time.

opBNB Test Result - Live sync 14K blocks, from 33180000 to 33194139.

In the case of opBNB, the execution time, state root calculation time, and total time for block insertion are all relatively small. Prefetching optimization doesn't show clear benefits for opBNB. This could be due to the small world state tree of opBNB. When opBNB runs on a machine with 128GB of memory, most trie nodes are already in memory, making prefetch optimization ineffective.

Changes

Notable changes:

Potential Impacts

gakonst commented 3 months ago

Have you guys benchmarked this work yet? Pretty exciting and stuff we've talked about before, keen to see how well it does as state root is by far the bottleneck...

keefel commented 3 months ago

Have you guys benchmarked this work yet? Pretty exciting and stuff we've talked about before, keen to see how well it does as state root is by far the bottleneck...

Thank you for being so interested. We are currently conducting performance tests and will soon release the relevant data publicly.