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

Update scores from uint64 to uint #60

Merged
merged 2 commits into from
Nov 13, 2023
Merged

Conversation

juliangruber
Copy link
Member

@juliangruber juliangruber commented Nov 12, 2023

uint256 is cheaper than uint64, this reduces cost by ~1.5%

See also https://www.linkedin.com/pulse/solidity-gas-golfing-1-uint8-vs-uint256-sudeep-sagar/

cc @AmeanAsad

test_TransferScheduled() (gas: -25169 (-0.997%)) 
test_SetScoresMultipleCalls() (gas: -31425 (-1.293%)) 
test_SetScoresMultipleParticipants() (gas: -29157 (-1.432%)) 
test_SetScoresFractions() (gas: -29135 (-1.482%)) 
test_RewardBurner() (gas: -29136 (-1.492%)) 
test_rewardsScheduledFor() (gas: -29030 (-1.496%)) 
test_MinBalanceForTransfer() (gas: -29115 (-1.502%)) 
test_SetScores() (gas: -29129 (-1.504%)) 
test_Reward() (gas: -29242 (-1.506%)) 
test_AvailableBalance() (gas: -29219 (-1.524%)) 
test_ReleaseReward() (gas: -28898 (-1.525%)) 
test_AdvanceRoundCleanUp() (gas: -29030 (-1.598%)) 
test_SetScoresTooBigHistoric() (gas: -29153 (-1.606%)) 
test_SetScoresOverflow() (gas: -28792 (-1.611%)) 
test_AdvanceRound() (gas: -28775 (-1.612%)) 
test_SetNextRoundLength() (gas: -28819 (-1.613%)) 
test_SetScoresEmptyRound() (gas: -28902 (-1.622%)) 
test_SetScoresTooBig() (gas: -29023 (-1.624%)) 
test_AddMeasurements() (gas: -28863 (-1.634%)) 
test_SetScoresNotEvaluator() (gas: -28884 (-1.639%)) 
test_SetRoundRewardNotAdmin() (gas: -28886 (-1.640%)) 
test_SetScoresUnfinishedRound() (gas: -28884 (-1.641%)) 
test_SetRoundReward() (gas: -28842 (-1.641%)) 
test_GasSetScores() (gas: -134881 (-1.755%)) 
Overall gas change: -800389 (-1.553%)

Copy link
Contributor

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

uint256 is cheaper than uint64, this reduces cost by ~1.5%

Wow, that's rather counterintuitive!

Could you please double-check that the gas cost savings also apply when there are thousands of scores?

@juliangruber
Copy link
Member Author

test_GasSetScoresManyParticipants() (gas: -23870849 (-9.853%))

This tests 1k participants, called 100 times in succession. Apparently smaller types are only cheaper if they're aligned so that they consume less space together (eg in a struct). Otherwise, there's an overhead associated with smaller types, since computation is necessary after reading it, since multiple entries can fit into one slot (vs a uint256 consumes the whole slot)

@juliangruber juliangruber merged commit 52a8291 into main Nov 13, 2023
1 check passed
@juliangruber juliangruber deleted the gas/uint-round-index branch November 13, 2023 14:46
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