The linked for loops evaluate their limit inefficiently on each iteration.
Example:
for (i = 0; i < WISE_LENDING.getPositionBorrowTokenLength(_nftId); ++i) {
Recommendation:
We advise the statements within the for loop limits to be relocated outside to a local variable declaration that is consequently utilized for the evaluations to significantly reduce the codebase's gas cost. We should note the same optimization is applicable for storage reads present in those limits as they are newly read on each iteration (i.e. length members of arrays in storage).
FMH-03C: Inefficient Loop Limit Evaluations
Description:
The linked
for
loops evaluate their limit inefficiently on each iteration.Example:
Recommendation:
We advise the statements within the
for
loop limits to be relocated outside to a local variable declaration that is consequently utilized for the evaluations to significantly reduce the codebase's gas cost. We should note the same optimization is applicable for storage reads present in those limits as they are newly read on each iteration (i.e.length
members of arrays in storage).