You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When looping over an array the condition of the loop is checked for every iteration. If you read the length of a storage variable multiple times it can get quite expensive. Instead, cache the length of memory and check that.
// bad
for (uint i; i < arr.length; i++) {
}
// good
uint length = arr.length;
for (uint i; i < length; i++) {
}
There are quite a number of instances where this can be used. Just search for "for (" and you'll find them.
G-02: cache storage variables that are read multiple times within a function
Whenever you read the same storage variable twice, you should cache it in memory. It will save you a SLOAD.
An example would be platformFee in _earmarkRewards()L526-L528
The text was updated successfully, but these errors were encountered:
Gas Report
G-01: cache array length in for loops
When looping over an array the condition of the loop is checked for every iteration. If you read the length of a storage variable multiple times it can get quite expensive. Instead, cache the length of memory and check that.
There are quite a number of instances where this can be used. Just search for "for (" and you'll find them.
G-02: cache storage variables that are read multiple times within a function
Whenever you read the same storage variable twice, you should cache it in memory. It will save you a SLOAD.
An example would be
platformFee
in_earmarkRewards()
L526-L528The text was updated successfully, but these errors were encountered: