<!-- canonical: https://0xsimao.com/findings/maple-finance-iii-private-cache-uncheck-gas -->

# pool-v2-private: cache list length in memory and uncheck i_ to save gas.

Low/Info · Three Sigma · Institutional lending · 10th April, 2024

Finding 3S-MAPLE-N10 of the Maple Finance security review.

- Protocol: https://maple.finance/
- Report: /reports/maple-finance-iii-2024
- Source: https://cdn.sanity.io/files/qoqld077/production/36dbe5ca76da3d2392bcee581548067705b8bd36.pdf

---

### Description

In the PoolManager contract, function setIsLoanManager(): variable
loanManagerList.length could be held in memory preventing multiple storage reads
during the for loop. The ++i could also be unchecked for additional gas savings.

### Recommendation

Cache the array length and uncheck the ++i. This function could also receive a hint with
the index of the loan manager in the loanManagerList, preventing the for loop that
iterates through the list, resulting in additional gas savings.

### Status

Acknowledged by the team.

---

Related findings:

- [Variables should be cached to memory to save gas](https://0xsimao.com/findings/metazero-ii-variables-cached-memory-gas): MetaZero Staking
- [Saving parameters in memory without using them spends gas](https://0xsimao.com/findings/fuji-finance-saving-memory-spends-gas): Fuji Finance
- [In glAVAX, checking that amount > 0 earlier can save some gas](https://0xsimao.com/findings/glacier-avax-checking-earlier-gas): Glacier
- [Storage variables should be cached whenever possible to save gas](https://0xsimao.com/findings/glacier-storage-cached-whenever-gas): Glacier
