Gas Optimizations #265
Labels
bug
Something isn't working
duplicate
This issue or pull request already exists
G (Gas Optimization)
1. Cache array length in loops instead of computing length in every iteration
While looping through array, the array length can be cached to save gas instead of computing length in each array iteration.
for eg.
2. Prefix increment (
++i
) is cheaper than postfix increment (i++
)Using prefix increment is saves small amount of gas than postfix increment because it returns the updated value hence doesn't requires to store intermediate value. This can be more significant in loops where this operation is done multiple times.
for eg.
3.Cache compute of
address(this).balance
in ternary operator to save gas instead of evaluating it twiceThe text was updated successfully, but these errors were encountered: