Skip to content

Anvil Write Performance Issue #4399

@PhilippLgh

Description

@PhilippLgh

Component

Anvil

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (e2fa2b5 2023-02-19T00:05:02.282096Z)

What command(s) is the bug in?

No response

Operating System

None

Describe the bug

Anvil seems to have big performance issues when lots of data are written:

Test Contract

contract TestContract{

  mapping(uint => uint) someData;

  function writeData(uint256[] memory numbersA, uint256[] memory numbersB) public {
    for (uint i = 0; i < numbersA.length; i++) {
      someData[numbersA[i]] = numbersB[i];
    }
  }

}

Writing Data in chunks of 150 + 150 uint

  let t0 = Date.now()
  for ([numbersA, numbersB] of chunk) {
    console.log('write data chunk', i++, data.length, 'after', Date.now()-t0, 'ms')
    tx = await contract.writeData(numbersA, numbersB)
    receipt = await tx.wait()
  }

Result console.log output

writing chunks 60
write data chunk 0 150 after 0 ms
write data chunk 1 150 after 26 ms
write data chunk 2 150 after 43 ms
write data chunk 3 150 after 62 ms
write data chunk 4 150 after 79 ms
write data chunk 5 150 after 93 ms
write data chunk 6 150 after 110 ms
write data chunk 7 150 after 126 ms
write data chunk 8 150 after 146 ms
write data chunk 9 150 after 164 ms
write data chunk 10 150 after 181 ms
write data chunk 11 150 after 195 ms
write data chunk 12 150 after 212 ms
write data chunk 13 150 after 227 ms
write data chunk 14 150 after 243 ms
write data chunk 15 150 after 263 ms
write data chunk 16 150 after 4287 ms
write data chunk 17 150 after 8322 ms
write data chunk 18 150 after 12368 ms
write data chunk 19 150 after 16414 ms
write data chunk 20 150 after 20449 ms
write data chunk 21 150 after 24474 ms
write data chunk 22 150 after 24507 ms
write data chunk 23 150 after 28534 ms
write data chunk 24 150 after 32570 ms
write data chunk 25 150 after 36616 ms
write data chunk 26 150 after 40657 ms

Subsequent writes on same node will be incredibly slow and node needs to be restarted.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Completed

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions