Open 0xScratch opened 1 year ago
Link Height tasks by mentioning a task ID in the pull request title or commit messages, or description and comments with the keyword
link
(e.g. "Link T-123").💡Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.
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