Inefficient Loop Operations in DebtManager
In DebtManager, there are several loop operations. The reason is that the array
structure is used to store lenders
to facilitate sorting. However, in practice, if the lenders
array becomes very large, the overhead of many functions in the entire contract will increase significantly.
Currently, the sorting method used is bubble sort. This is more gas efficient for small arrays, but it consumes more gas for larger arrays. Given that the lenders
are used in multiple functions and have a significant impact, it is recommended to use a mapping
structure to store lenders
.
For sorting, according to the best implementation, one possible suggestion is to perform it off chain. In this way, the overall overhead will be similar, regardless of how large the lenders
array is.