NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7.13k stars 1.36k forks source link

Investigate Hardhat's memory performance #3471

Open fvictorio opened 1 year ago

fvictorio commented 1 year ago

We know that there are memory leaks when snapshots are used, but we should do a proper profiling of how Hardhat's memory usage behaes in different scenarios.

Marking this as blocked until rethnet, because it doesn't make sense to invest time in this before that.

Related issues:

Whytecrowe commented 1 month ago

Issue ("JavaScript heap out of memory") still persists when running hardhat coverage. Started happening after updates to the below versions.

Versions: "solidity-coverage": "0.8.12" "hardhat": "2.22.5"

Adding export NODE_OPTIONS=--max-old-space-size=4096 before running hardhat coverage produces Killed output instead of heap out of memory. Not sure this is the right solution though.

alcuadrado commented 1 month ago

Does it also fail if you only upgrade hardhat and not solidity-coverage?

Whytecrowe commented 1 month ago

Does it also fail if you only upgrade hardhat and not solidity-coverage?

Thanks for the suggestion! Tried this now and don't seem to fail so far, but it's not a full run of all contracts at this time. Will keep working and get back on this.

Whytecrowe commented 1 month ago

After adding all the tests back, I am still getting the same error.

cgewecke commented 1 month ago

Hi @Whytecrowe, (I help maintain solidity-coverage)

Is it possible to increase your memory allocation to 8192 and see if it works / the mem usage is bounded?

- export NODE_OPTIONS=--max-old-space-size=4096
+ export NODE_OPTIONS=--max-old-space-size=8192

You may also be able to reduce the plugin's runtime memory footprint by setting the measureStatementCoverage option to false in .solcover.js.

There's more info about this in the plugin's FAQ at the link below:

faq.md#running-out-of-memory

Whytecrowe commented 1 month ago

Hey @cgewecke , thank you for your answer. I have tried both methods, and the issue still persists. When I enlarge old space size, instead of "heap out of memory" I just get a single word message - "Killed", but the coverage test fails at the same place. Adding measureStatementCoverage flag didn't help either. I went through the FAQ, but none of it seems to help.

We do not have any new contracts, just updated OZ packages, but the amount of contracts stayed the same, and before, with older Hardhat and OZ contracts we haven't had any issues.

Is there anything else that may help here?

cgewecke commented 1 month ago

@Whytecrowe Commented in your PR here:

https://github.com/zer0-os/zNS/pull/109

It looks like the issue is tied to a stress test using a huge (100k chars) string. Maybe there's a memory problem somewhere in EDR when the vm step listener is attached and there's a huge transaction frame or something?

Whytecrowe commented 1 month ago

@Whytecrowe Commented in your PR here:

https://github.com/zer0-os/zNS/pull/109

It looks like the issue is tied to a stress test using a huge (100k chars) string. Maybe there's a memory problem somewhere in EDR when the vm step listener is attached and there's a huge transaction frame or something?

I just tried this before your message, and it worked. The link on how to skip it for coverage only is super helpful. Thank you for all the help!