-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
--optimize-runs
for Yul mode
#11708
Comments
--optimize-runs
for Yul contracts--optimize-runs
for Yul mode
I took a quick look at the CLI code and it's just that the So this should be very simple to fix - just pass the option down to Fortunately this does not happen in Standard JSON mode and also this is the only optimizer option that is ignored without giving any feedback. I'd classify it as a bug rather than a missing feature because this is a discrepancy with how Standard JSON works. It should have been changed back when the option was being added for Yul in Standard JSON. |
Cool, thanks! Until recently, it would not have an effect anyway since it is mainly used by the opcode-based optimizer |
I'd think so too but I was curious myself how far back it goes and checked that via Standard JSON - I can reproduce this difference as far back as 0.6.0. 0.5.17 is the last version that does not have it |
Abstract
The Solidity compiler (solc) ignores the
--optimize-runs
parameter in Yul mode in favor of a list of Yul-specific optimizations. However, the default Yul optimizer list does not include runs-based optimizations that can improve gas efficiency, most notably for high numbers of expected runs.Motivation
It seems that some, if not all, of the optimizations done on Solidity contracts expecting a high number of runs are not included when compiling for Yul, so those using
solc
to compile Yul contracts aimed at high run counts are penalized.Remix has a "Runs" field for Yul contracts and is able to apply these optimizations. Here is one example:
When compiled with Runs = 1 in Remix, the output becomes
When compiled with Runs = 100000 in Remix, the "PUSH4 0xABC12345 PUSH1 224 SHL" gets compressed into a PUSH32 for gas savings:
Using
solc
does not give this result (commandsolc --yul --yul-dialect evm --optimize
)solc
works better than Remix for a number of other optimizations (for instance, Remix will output multipleJUMPDEST
s in succession). Nonetheless, the Yul compiler would benefit greatly if some of these high-runs optimizations could be included.Specification
The
--optimize-runs
option should be made available in Yul mode.--optimize --optimize-runs 100000
for the Yul code above should contain the PUSH compression optimization given above, for example.Backwards Compatibility
This feature will not introduce backward compatibility issues because the
--optimize-runs
option would be new for Yul mode.The text was updated successfully, but these errors were encountered: