Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizer low runs value doubles gas cost of function #14069

Closed
vimwitch opened this issue Mar 24, 2023 · 1 comment
Closed

Optimizer low runs value doubles gas cost of function #14069

vimwitch opened this issue Mar 24, 2023 · 1 comment
Assignees
Projects

Comments

@vimwitch
Copy link

Description

I'm not sure if this is a bug, or extreme edge behavior of the optimizer so I'm seeking advice here. I have a hash function implemented here. With low runs the cost of executing is roughly doubled. For example, the cost of an addmod operation goes from 22 gas to 52 gas (including assigment to stack).

I understand that low runs indicates to optimize for deployment cost instead of call cost, but is increasing the call cost this much expected behavior? It's not a huge problem because the library will deployed at a global location with the runs value set to 2**32-1, but it may confuse developers that consume the hash function as a package in a development environment.

Environment

  • Compiler version: 0.7.4, 0.8.4, 0.8.17
  • Target EVM version (as per compiler settings): Merge
  • Framework/IDE (e.g. Truffle or Remix): Remix, Hardhat
  • EVM execution environment / backend / blockchain client: hardhat/remix vm
  • Operating system: OSX

Steps to Reproduce

I have a repository here reproducing the behavior. Specifically disabling the optimizer cuts the cost of executing the function by 2x (same with increasing runs to 2**32-1).

If you clone this repo run

npm i
npm t

and it will print info about costs. Change the hardhat.config.js file to disable the optimizer and run again and you'll see a different output.

Thanks

@github-actions github-actions bot added this to Triage in Solidity Mar 24, 2023
@matheusaaguiar
Copy link
Collaborator

matheusaaguiar commented Apr 3, 2023

@vimwitch I think this is more of a question/discussion for the language forum. As you noted

[...] low runs indicates to optimize for deployment cost instead of call cost [...]

Your repo uses 200 for the runs parameter, which is very low and thus, in my opinion, would justify the optimizer not caring about the addmod cost.
For example, if you use a value of 2**13 for the runs parameter, then the cost goes to 22.
I am closing this for now, but, please feel free to reply if you think this really is an issue.

Solidity automation moved this from Triage to Done Apr 3, 2023
@matheusaaguiar matheusaaguiar self-assigned this Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Solidity
  
Done
Development

No branches or pull requests

2 participants