foundry-rs / foundry-rs/foundry
perf: `anvil_mine` is much slower than `hardhat_mine`
- Dominant language
- Rust
- Stars
- 10.6k
- Forks
- 2.6k
- Avg merge
- 16h 38m
- Merged PRs (30d)
- 511
Description
I attempted to move my testing from `hardhat node` to `anvil`. Some of my testing requires mining a large number of blocks. `anvil_mine` execution time seems to scale linearly relative to block count, whereas `hardhat_mine` with `hardhat node` is nearly constant. See the following benchmarks:
#### Anvil
```Python
In [1]: import timeit
In [2]: [timeit.timeit(stmt=(f'chain.mine({i})'), globals=globals(), number=50) for i in [1, 1
...: 0, 100, 1000]]
Out[2]:
[0.07101033299113624,
0.39050891700026114,
6.034164124997915,
276.3122650830046]
```
#### Hardhat
```Python
In [1]: import timeit
In [2]: [timeit.timeit(stmt=(f'chain.mine({i})'), globals=globals(), number=50) for i in [1, 1
...: 0, 100, 1000]]
Out[2]:
[0.10906625000643544,
0.09370395800215192,
0.0902477499912493,
0.08129970800655428]
```
I'm using:
* `anvil 0.1.0 (0e33b3e 2023-07-26T00:26:08.161934000Z)`
* `hardhat 9.6.7`
* `ape 0.6.14` (for testing)
https://github.com/foundry-rs/foundry/blob/41bae8e6265e905f73c3f4eac14a5ba9275417a4/anvil/src/eth/api.rs#L1421-L1440
Contributor guide
Research direction
Start with anvil/src/eth/api.rs at lines 1421-1440 and reproduce the reported anvil_mine benchmarks using the issue's block counts. Compare execution time across those cases and consider the work complete when mining large batches no longer shows the reported linear slowdown relative to the benchmark behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- blockchain, devtools, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100