-
-
Notifications
You must be signed in to change notification settings - Fork 125
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 exp2 with batching bit checks #77
Conversation
Ooh this is cool, thanks a lot for making this PR! I will review later. Re gas reports - yeah, a discussed in #70, the current solution is to do what I did in the test/gas-estimations branch - add a bunch of The crux of the problem is that |
@PaulRBerg you could make transactions to view methods to make gas reporter work properly, but you will need to subtract calldata cost and |
I tested this with the following functions: function measure_exp2(uint256 x) external pure returns (uint256 result) {
result = x.exp2();
}
function measure_exp2_v2(uint256 x) external pure returns (uint256 result) {
result = x.exp2_v2();
} Where
In this case,
In this case, So it looks like batching bit check lowers the gas costs only in some cases. I think the best way to determine whether this PR should be merged or not is to rebase the test/gas-estimations branch to use the latest implementations from Side note: I'm thinking to tentatively merge this on the |
In the meantime, two quick questions for you @k06a:
|
@PaulRBerg checking to
|
I suspect rewriting this in solidity assembly could win tens of percentages |
BTW example |
This is a good point. In this case, it does seem like that this PR's optimization will lead to a gas reduction more often than it will lead to a gas increase. Also when the gas is reduced is reduced more than it increases when it is increased. |
Going to merge this onto Thanks for your contribution, @k06a! |
Turns out that this PR introduced a bug in the @andreivladbrg fixed this in #179. |
@PaulRBerg I sincerely apologise for the bug, it was made unintentionally |
No worries, @k06a! I never assumed otherwise |
I didn't find an easy way to build a gas report.