hard20 pts · first answer countsgas-optimisationsolidity
Expensive loop over storage
Which change saves the most gas in this function?
uint256[] public rewards;
uint256 public total;
function sum() external {
for (uint256 i = 0; i < rewards.length; i++) {
total += rewards[i];
}
}Discussion 0
Join free to post in the discussion.
Related questions
- storage, memory, calldataBlockchain Developer
- Why emit eventsBlockchain Developer
- What msg.sender isBlockchain Developer
- Wei and etherBlockchain Developer
- view vs pureBlockchain Developer
- Sending ETH to a functionBlockchain Developer
- receive vs fallbackBlockchain Developer
- Reading a missing mapping keyBlockchain Developer