perf(anvil): batch mine empty blocks to skip redundant state root computation#13432
Open
0xMars42 wants to merge 2 commits intofoundry-rs:masterfrom
Open
perf(anvil): batch mine empty blocks to skip redundant state root computation#134320xMars42 wants to merge 2 commits intofoundry-rs:masterfrom
0xMars42 wants to merge 2 commits intofoundry-rs:masterfrom
Conversation
d9ebdac to
827d549
Compare
…pty_blocks receipts_root used Default::default() (B256::ZERO) instead of EMPTY_ROOT_HASH for empty blocks. transactions_root had the same issue but was masked by create_block() overwriting it. Fix both for correctness.
827d549 to
b5ec295
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
anvil_mine(n)callsdo_mine_block()in a loop — each iteration spins up aTransactionExecutor, commits state, and recomputes the Merklestate_root, even when the pool is empty and there's nothing to execute. Foranvil_mine(1000)that's 1000 redundant state root computations.This adds a
mine_empty_blocks()fast path that kicks in when the pool is empty andnum_blocks > 1. It reuses the parent'sstate_root(no state transitions = same root) and builds block headers directly, skipping the EVM entirely. Everything else — base fee decay, blob gas, notifications, state history snapshots — is still computed per-block in the loop so downstream behavior doesn't change.anvil_mine(1)always goes through the existing path.anvil_mine(1000)with an empty pool completes in ~1.5s (debug build, Windows). Before the optimization this took ~276s as reported in #5499.Fixes #5499.