morpho-data-structures icon indicating copy to clipboard operation
morpho-data-structures copied to clipboard

Possible optimization in heap size

Open QGarchery opened this issue 3 years ago • 3 comments

Found by @MathisGD.

Currently the heap size is changing at each insert, remove, and decrease operation. When it reaches _maxSortedUsers, it is divided by 2. The informal goal is to distribute high liquidity evenly on the branches of the heap, in order to maximize the total liquidity that is in the heap.

One other idea would be distribute the incoming liquidity "randomly" on the last nodes before _maxSortedUsers. This means that the size of the heap would only change up to _maxSortedUsers and then stay the same, potentially saving one SSTORE for each operation. Another potential benefit would be that the introduced randomness would mostly prevent worst case scenarios for the incoming liquidity. Note that there is no real need for the randomness here to be truly random, and we could use a pseudo-random function instead.

QGarchery avatar Aug 08 '22 10:08 QGarchery

WIP there #76

MathisGD avatar Apr 19 '23 14:04 MathisGD

What's the state of this issue?

MerlinEgalite avatar Apr 26 '23 13:04 MerlinEgalite

It has to be implemented ! I started something in #76, but it was far from being ready. I might go back to it when I will have a little bit more bandwidth.

MathisGD avatar Apr 26 '23 13:04 MathisGD