The linked for loops evaluate their limit inefficiently on each iteration.
Example:
for (uint256 i = 0; i < WISE_LENDING.getPositionLendingTokenLength(_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).
WSH-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).