The linked for loop evaluates its limit inefficiently on each iteration.
Example:
for (uint256 i; i < baskets.length;) {
Recommendation:
We advise the statements within the for loop limit to be relocated outside to a local variable declaration that is consequently utilized for the evaluation to significantly reduce the codebase's gas cost. We should note the same optimization is applicable for storage reads present in such limits as they are newly read on each iteration (i.e. length members of arrays in storage).
BMR-02C: Inefficient Loop Limit Evaluation
Description:
The linked
for
loop evaluates its limit inefficiently on each iteration.Example:
Recommendation:
We advise the statements within the
for
loop limit to be relocated outside to a local variable declaration that is consequently utilized for the evaluation to significantly reduce the codebase's gas cost. We should note the same optimization is applicable for storage reads present in such limits as they are newly read on each iteration (i.e.length
members of arrays in storage).