-
Notifications
You must be signed in to change notification settings - Fork 597
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 gas for _getFraction in AmountDeriver #384
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4d5c1f0
Optimize gas for _getFraction in AmountDeriver
Chomtana 0410f66
Add more credit inplace of @hrkrshnn + @axic
Chomtana dea98a6
Change file name to follow the original pattern
Chomtana 341d9e4
Revert to just optimized mulmod check
Chomtana 6d99451
Remove gt as gt 0 = truth
Chomtana 4cd8c9e
Add Disambiguation & Other Notes
Chomtana 4ae3e3e
Reference AmountDerivationErrors.sol
Chomtana a2c1d58
Move constants to ConsiderationConstants
Chomtana 5a8575d
Remove credit
Chomtana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this does anything? The double
iszero(iszero(...))
should be optimised out.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just
mulmod(value, numerator, denominator)
should be worked as @0age said since we need to test whethermulmod(value, numerator, denominator)
is not zero and it is unsigned which meansmulmod(value, numerator, denominator)
is truthyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean if the change does anything gas wise. The double iszero should be removed by the optimiser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does by removing unnecessary exact variable.
exact := iszero(mulmod(value, numerator, denominator))
if iszero(exact) {
...
}
Don't sure whether optimiser can remove double iszero that is stored into intermediate variable first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many optimiser stages, including one which operates on opcode level, where known stack movement are supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have just tested gas on remix using 2 separate contracts with same function name getFraction for both case and adding
a global variable assignment to the end
Normal case (2, 5, 10)
Before: 24189 gas
After: 24176 gas
Revert case (2, 5, 8)
Before: 21845 gas
After: 21804 gas