Gas Optimization #38
Labels
bug
Something isn't working
G (Gas Optimization)
sponsor acknowledged
Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Gas Optimizations Report
Table of contents
Gas Findings
[Gas-1] Do not cache msg.sender
We recommend not to cache msg.sender since calling it is 2 gas while reading a variable is more.
[Gas-2] Use != 0 instead of > 0
Using != 0 is slightly cheaper than > 0. We recommend to replace > with != in the following places:
[Gas-3] Rearrange state variables
You can change the order of the storage variables to decrease memory uses. This is because the new suggested new orders will use less storage slots.
old number of slots: 17
new number of slots: 15
the new order of types is
1. ArrayTypeName - address
2. uint256
3. uint256
4. uint256
5. uint256
6. uint256
7. ArrayTypeName - Epoch
8. IERC20
9. uint256
10. uint256
11. uint256
12. string
13. string
14. address
15. uint8
16. bool
17. address
AuraVestedEscrow.sol:
old number of slots: 7
new number of slots: 6
the new order of types is
1. IERC20
2. IAuraLocker
3. uint256
4. uint256
5. uint256
6. address
7. bool
BoosterOwner.sol:
old number of slots: 9
new number of slots: 8
the new order of types is
1. uint256
2. uint256
3. address
4. bool
5. bool
6. address
7. address
8. address
9. address
10. address
CrvDepositor.sol:
old number of slots: 13
new number of slots: 12
the new order of types is
1. uint256
2. uint256
3. uint256
4. uint256
5. uint256
6. uint256
7. address
8. bool
9. address
10. address
11. address
12. address
13. address
[Gas-4] Unnecessary index init
In for loops you initialize the index to start from 0, but it already initialized to 0 in default and this assignment cost gas. It is more clear and gas efficient to declare without assigning 0 and will have the same meaning:
The text was updated successfully, but these errors were encountered: