Update ReservesSetupHelper.sol: Optimized Gas #904
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Types of changes made:
1st - Struct Packing - Aligning booleans with the address in order to decrease the slots which kinds of save gas. Refer this -> https://dev.to/javier123454321/solidity-gas-optimizations-pt-3-packing-structs-23f4
2nd -
uint256 i = 0;
touint256 i
- This change too saves some gas cuz the default value of all unsigned integers is 0. Thus, I find no need to initialize it3rd - using
unchecked
- After the Solidity 0.8 version, Solidity compilers started using overflow/underflow checks which is gas costly. But I find that there's no chance of any underflow/overflow in this loop, sounchecked
can be used in this purpose. (Tho, I still suggest to take a brief look into this change)4th -
i++
to++i
- Saves gas, just make sure it doesn't messes up with the code's logic.Refer this for 2nd, 3rd and 4th change -> https://gist.github.com/grGred/9bab8b9bad0cd42fc23d4e31e7347144#for-loops-improvement