foundry: perf(`anvil`): enhance block mining performance in Anvil node for high throughput and efficiency

Component

Anvil

Describe the feature you would like

I propose a performance enhancement for the Anvil node, specifically targeting the efficiency of block mining. Through some tests I’ve observed that while Anvil demonstrates impressive transaction processing capabilities, there’s a noticeable disparity in throughput efficiency primarily attributed to the time spent mining blocks. This feature request seeks optimizations in Anvil’s block mining to reduce execution time, thereby increasing the overall transactions per second (TPS) throughput and making the node more suitable for applications requiring high transaction processing speeds as well as frequent mining of blocks.

Additional context

Anvil version: 0.2.0 (2cf84d9 2024-02-07T00:15:49.622159000Z)

To illustrate the current performance characteristics and provide a basis for this request, I conducted a test using a Uniswap V3 transaction replay script. The findings highlight a significant potential for performance gains in block mining processes. For instance, when increasing the nullSwapsPerBlock from 1 to 2000, the average TPS improved dramatically(by a factor of 7x), indicating that the node spends a significant portion of time mining blocks vs actual transaction execution. To replicate this test:

  1. clone this repo anvil-backtester, install deps(pnpm i)
  2. start the anvil node: pnpm anvil:start
  3. run the test script: pnpm test:anvil-memory with nullSwapsPerBlock set to 1 and then again set to 2000 and observe results similar to the following indicating significant overhead in mining blocks:
{
  blocksToMine: 25,
  nullSwapsPerBlock: 1,
  totalTxs: 50,
  executionTime: 0.084,
  averageTPS: 595.2380952380952,
  averageTimePerTx: 1.6800000000000002
}
{
  blocksToMine: 25,
  nullSwapsPerBlock: 2000,
  totalTxs: 100000,
  executionTime: 24.747,
  averageTPS: 4040.8938457186728,
  averageTimePerTx: 0.24747000000000002
}

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

going to merge this one with https://github.com/foundry-rs/foundry/issues/5499 and to track potential hardhat behavior, @mshakeg please reopen if you think they should be addresses differently. thank you!

@grandizzy sure, though have you done some profiling to determine why the large TPS discrepancy? If much time is spent mining blocks(and computing merkl roots when mined for example) that could be disabled in a local node then agreed with adding an option to skip these computations for an even more performant local node.

I think this explain it https://github.com/foundry-rs/foundry/issues/5499#issuecomment-1663487217