To optimize the for loop and make it consume less gas, i suggest to:
If a variable is not set/initialized, it is assumed to have the default value (0 for uint, false for bool, address(0) for address…). Explicitly initializing it with its default value is an anti-pattern and wastes gas.
Use ++i instead of i++, which is a cheaper operation (in this case there is no difference between i++ and ++i because we dont use the return value of this expression, which is the only difference between these two expression).
As an example:
for (uint256 i = 0; i < numIterations; ++i) {
should be replaced with
for (uint256 i; i < numIterations; ++i) {
and also i suggest to save the variable that load and array in a new variable like
for (uint256 i = 0; i < protectedTokens.length; i++) {
change to :
uint256 _protectedTokens=protectedTokens.length;
for (uint256 i = 0; i < _protectedTokens; i++) {
To optimize the for loop and make it consume less gas, i suggest to:
If a variable is not set/initialized, it is assumed to have the default value (0 for uint, false for bool, address(0) for address…). Explicitly initializing it with its default value is an anti-pattern and wastes gas.
Use ++i instead of i++, which is a cheaper operation (in this case there is no difference between i++ and ++i because we dont use the return value of this expression, which is the only difference between these two expression).
As an example:
should be replaced with
and also i suggest to save the variable that load and array in a new variable like
change to :
i suggest to change code below: https://github.com/Badger-Finance/vested-aura/blob/v0.0.2/contracts/MyStrategy.sol#L118 https://github.com/Badger-Finance/vested-aura/blob/v0.0.2/contracts/MyStrategy.sol#L300 https://github.com/Badger-Finance/vested-aura/blob/v0.0.2/contracts/MyStrategy.sol#L317 https://github.com/Badger-Finance/badger-vaults-1.5/blob/0.1.0/contracts/BaseStrategy.sol#L158