Skip to content

perf(anvil): Memory consumption steadily increases during prolonged transaction replays #6017

@mshakeg

Description

@mshakeg

Component

Anvil

Describe the feature you would like

Description

I've been utilizing Anvil 0.2.0 (5be158b 2023-10-02T00:23:45.472182000Z) as a local Ethereum node for a Uniswap V3 backtester project. The backtester replays all transactions for a specific Uniswap V3 Pool. However, I've noticed a consistent and steady increase in memory usage over time as more transactions are replayed, even with the --prune-history flag enabled. Below is the exact command I'm using to start the anvil node:

anvil --prune-history --timestamp 1619820000 --order fifo --code-size-limit 4294967296 -m "test test test test test test test test test test test junk" --gas-limit 100000000000 --gas-price 0 --base-fee 0

Observations

  1. The memory consumption increases steadily with the replaying of transactions.
  2. When replaying transactions for backtesting, I first set the block's timestamp using evm_setNextBlockTimestamp and then utilize evm_mine to mine the block.
  3. After around 10 minutes of running, the Docker stats indicate that Anvil has consumed around 9.247GiB of memory:
de526102010a   web3-backtester-anvil-1-1        98.78%    9.247GiB / 62.01GiB   14.91%    12.3MB / 15.6MB   4.77MB / 0B       11
  1. I'm only deploying contracts at the very start and the rest(and vast majority) of the runtime is spent replaying transactions for the backtest.

Expected Behavior

Stable memory consumption or a slower, more controlled growth in memory usage over time when replaying transactions.

Possible Solutions

While I'm not certain about the root cause, I'd appreciate if the team could investigate:

  1. Whether transaction replays might be causing memory leaks or if there are specific internal data structures growing unbounded.
  2. If the --prune-history flag could be further optimized or if there's a possibility of introducing additional pruning or memory management features.

Additional context

Environment Details

  • Anvil Version: 0.2.0
  • Host: EC2 instance (8 vCPU, 64 GB RAM)
  • Docker container

Metadata

Metadata

Assignees

Labels

C-anvilCommand: anvilT-bugType: bugT-perfType: performance

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions