Closed giovannifranchi closed 3 months ago
Variables in memory use 32 bytes in any case because of how Solidity works. Using a uint8
instead of a uint256
actually increases the cost of operations since under the hood solidity converts the uint8
in uint256
. As an example a made a dummy contract which performs a for loop of 50 iterations.
As we can see the transaction cost of the loop performed with uint256 is 46538
while for uint8 is 46822
For what concerns ++i instead of i++ I can confirm there is a small gas saving (46538 - 46310 = 228) which could be considered negligible, especially considering contracts operate on L2s and the contract I made performs 50 iterations. Nonetheless I will apply this change.
Changes implemented: