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

Reduced mload in PrizeSplit #228

Closed

Conversation

asselstine
Copy link
Contributor

@asselstine asselstine commented Oct 14, 2021

@@ -132,8 +132,7 @@ abstract contract PrizeSplit is IPrizeSplit, Ownable {
uint256 prizeSplitsLength = _prizeSplits.length;

for (uint8 index = 0; index < prizeSplitsLength; index++) {
PrizeSplitConfig memory split = _prizeSplits[index];
_tempTotalPercentage = _tempTotalPercentage + split.percentage;
_tempTotalPercentage = _tempTotalPercentage + _prizeSplits[index].percentage;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_tempTotalPercentage = _tempTotalPercentage + _prizeSplits[index].percentage;
_tempTotalPercentage += _prizeSplits[index].percentage;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure this is cheaper since _prizeSplits is in storage, so each time we access _prizeSplits[index].percentage, it will cost us 200 in gas.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either way it's one word

@@ -132,8 +132,7 @@ abstract contract PrizeSplit is IPrizeSplit, Ownable {
uint256 prizeSplitsLength = _prizeSplits.length;

for (uint8 index = 0; index < prizeSplitsLength; index++) {
PrizeSplitConfig memory split = _prizeSplits[index];
_tempTotalPercentage = _tempTotalPercentage + split.percentage;
_tempTotalPercentage = _tempTotalPercentage + _prizeSplits[index].percentage;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure this is cheaper since _prizeSplits is in storage, so each time we access _prizeSplits[index].percentage, it will cost us 200 in gas.

@asselstine asselstine closed this Oct 14, 2021
@asselstine asselstine force-pushed the pool-1802-prizesplitsol_totalprizesplitpercentagea branch from 36ca245 to 4e1d565 Compare October 14, 2021 03:58
@asselstine asselstine deleted the pool-1802-prizesplitsol_totalprizesplitpercentagea branch October 14, 2021 03:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants