Gas Optimizations #327
Labels
bug
Something isn't working
duplicate
This issue or pull request already exists
G (Gas Optimization)
G01 - Comparison
> 0
is less gas efficient than!= 0
withuint256
inrequire
statementG02 - No need to initialize variables with default values
If a variable is not set, it is assumed to have the default value (0, false etc).
G03 - Variables that can be changed to
immutable
G04 - Cache array length before
for
loopOptimizing
for
loops by caching memory array length before loop, instead of calling it every time.G05 - Using ++i consumes less gas than i++
G06 -
unchecked
block can be used for gas efficiency of the expression that can't overflow/underflowCheck comments
G07 - Too long revert strings
Shortening revert strings to fit in 32 bytes will decrease deployment time gas and will decrease runtime gas when the revert condition has been met.
G08 - Named return vatiable
Removing unused named return variables can reduce gas usage and improve code clarity.
G09 - No needed
+=
No need to use
+=
instead of=
, sincetotalLocked[_recipient[i]]
always be0
here:G10 - Caching storage values in memory
Variables that are read multiple times in a code block can be cached and re-used instead of reading from storage to save gas.
The text was updated successfully, but these errors were encountered: