hardhat-gas-reporter icon indicating copy to clipboard operation
hardhat-gas-reporter copied to clipboard

Add option to report view & pure method gas usage

Open cgewecke opened this issue 2 years ago • 5 comments

We should be able to use estimateGas for these.

It impairs test speeds but this data is important for libraries.

(See prb-math 70)

cgewecke avatar Feb 04 '22 22:02 cgewecke

For the cases where speed is important you could add a toggle in the config to disable it (I think it should be enabled by default though).

cameel avatar Feb 04 '22 22:02 cameel

@cameel Do you think so?

I am inclined the other way because I've seen estimateGas really slow things down on Hardhat (by more than 2X which is what I would expect) and test suites make so many calls.

Definitely worth benchmarking on a large project.

cgewecke avatar Feb 04 '22 22:02 cgewecke

Ah, that's way more than I expected. If it really slows things down that much then yeah, it might make sense to keep if off by default.

BTW, let me know if you need help benchmarking it on some real-life projects. We have a nice setup in Solidity where we run a bunch of them (13+ mid to large projects, including OpenZeppelin, Uniswap v3, Gnosis, etc) in CI to test the compiler. As a part of this we can see a breakdown of how long each one took to run the whole test suite: https://app.circleci.com/pipelines/github/ethereum/solidity/22003/workflows/92d7ef3e-f94a-448c-9db1-16cc18d19e9a (all the t_native_test_ext_... jobs are such projects). The time includes compilation, dependency installation, etc. but on the upside it would also show how relevant the slowdown is compared to other factors.

cameel avatar Feb 04 '22 22:02 cameel

Oh fantastic, thank you @cameel

cgewecke avatar Feb 04 '22 22:02 cgewecke

Would be cool to have this!

sebastiantf avatar Aug 04 '22 06:08 sebastiantf

This would be very useful for SolidState.

ItsNickBarry avatar Nov 18 '22 02:11 ItsNickBarry

This has been added in the latest release (2.0). The relevant options look like this

gasReporter: {
  // This option executes an additional `eth_estimateGas` for every `eth_call`
  // detected by the reporter. If you have 1000's of tests setting it to true has a
  // noticeable performance impact
  reportPureAndViewMethods: true,

  // This option can add several seconds to test startup time if you have
  // 100's of contracts in your project. (It parses all the sources in your dependency tree
  // to identify state variable declarations)
  excludeAutoGeneratedGetters: true,
}

https://github.com/cgewecke/hardhat-gas-reporter/releases/tag/v2.0.0

cgewecke avatar Mar 14 '24 05:03 cgewecke