-
Notifications
You must be signed in to change notification settings - Fork 6k
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 seems to produce larger bytecode when run longer #2245
Comments
The documentation around the
The |
Acceptance criterion: Improve the documentation about the optimizer settings, especially the "runs" parameter. |
Issue Status: 1. Open 2. Started 3. Submitted 4. Done This issue now has a funding of 100.0 DAI (100.0 USD @ $1.0/DAI) attached to it.
|
Issue Status: 1. Open 2. Started 3. Submitted 4. Done Work has been started. has committed to working on this project to be completed 5 months, 4 weeks from now. |
Issue Status: 1. Open 2. Started 3. Submitted 4. Done Work for 100.0 DAI (100.0 USD @ $1.0/DAI) has been submitted by: @gdipri01 please take a look at the submitted work:
|
Fixed in #4048 |
Issue Status: 1. Open 2. Started 3. Submitted 4. Done The funding of 100.0 DAI (100.0 USD @ $1.0/DAI) attached to this issue has been approved & issued to @JonnyBurger.
|
I found a curious result when upgrading Truffle to Solidity 0.4.11 (via solc-js). It seems that the more the optimizer is run, the longer my bytecode gets. This suggests to me that the optimizer is adding instructions instead of removing them.
The contract in question is this one. This is Truffle's assertion library for its Solidity tests, which is so large that it could possibly overflow the block gas limit. This contract relies on the optimizer to ensure the that it can be deployed free and clear.
When upgrading from Solidity 0.4.8 to 0.4.11, I used the default/example configuration from here to specify my optimizer settings. That configuration, for me, looks like this:
With this configuration, exactly as it stands, this contract will overflow the block gas limit of
4712388
when deployed. The character length of the resulting bytecode is 35242 characters long. When I increase the number of runs the optimizer makes, curiously, the longer the code becomes. Inversely, if I run the optimizer as little as possible without turning it off, the shorter the resulting bytecode. Here's a list of findings:It would appear that the optimizer is optimizing for space/code length when turned on. However, if you run it (i.e., runs > 0), the more instructions or data it appears to add to the resulting bytecode. My only guess is that this is meant to optimize for transaction costs for certain transactions by replacing costly instructions with cheaper, less costly versions (though using more of them), but I haven't looked deeper.
One interesting result that I included in the table: runs
0
through13
all produce the same code length, but different bytecode. I'm unsure if this is significant, butruns = 14
is where I saw the first change in code length.For Truffle users, I plan to default to
runs = 0
as smaller code (i.e., ability to deploy) is more valuable than slightly cheaper transaction costs. I'll likely let users configure this option in the future.The text was updated successfully, but these errors were encountered: