VIS-2 / taobank-04-24

0 stars 0 forks source link

Store array length outside loops for efficiency #25

Open 0xMilenov opened 4 months ago

0xMilenov commented 4 months ago

Context

Vault::collaterals() LiquidationRouter::collaterals() VaultFactoryHelper::getVaultTvl() VaultFactoryHelper::getRedeemableVaults()

Description

When array length isn't cached, the Solidity compiler repeatedly reads it in every loop iteration. For storage arrays, this means an added sload operation costing 100 extra gas for each subsequent iteration. For memory arrays, it's an additional mload operation costing 3 extra gas post the first iteration.