Gas Optimizations #164
Labels
bug
Something isn't working
duplicate
This issue or pull request already exists
G (Gas Optimization)
wontfix
out of scope, a non-issue, or something already addressed
GAS
1. Improve logic
Move the following line from VaultTracker.sol#L155-L158:
2. Avoid unused returns
Having a method that always returns the same value is not correct in terms of consumption, if you want to modify a value, and the method will perform a
revert
in case of failure, it is not necessary to return atrue
, since it will never befalse
. It is less expensive not to return anything, and it also eliminates the need to double-check the returned value by the caller.Affected source code:
3.
++i
costs less gas compared toi++
ori += 1
++i
costs less gas compared toi++
ori += 1
for unsigned integer, as pre-increment is cheaper (about 5 gas per iteration). This statement is true even with the optimizer enabled.i++
incrementsi
and returns the initial value ofi
. Which means:But
++i
returns the actual incremented value:In the first case, the compiler has to create a temporary variable (when used) for returning
1
instead of2
I suggest using
++i
instead ofi++
to increment the value of an uint variable. Same thing for--i
andi--
Affected source code:
4.
delete
optimizationUse
delete
instead of set to default value (false
or0
).5 gas could be saved per entry in the following affected lines:
5. Reduce math operations
Use scientific notation (e.g. 10e17) rather than exponentiation (e.g. 10**18)
Change
2**256 - 1
totype(uint256).max
:The text was updated successfully, but these errors were encountered: