synthetix icon indicating copy to clipboard operation
synthetix copied to clipboard

Measure gas usage on L2 when adding synths - DebtCache Vs RealtimeDebtCache

Open i-stam opened this issue 4 years ago • 1 comments

Summary: Given the 9mil tx gas limit that exists on L2, we would like to investigate the impact of adding new synths on exchanging costs (in terms of gas). For this reason, we want also to check whether the enabling of DebtCach on L2 alleviates the problem or not.

Relevant Info

RealtimeDebtCache OVM instance: https://github.com/Synthetixio/synthetix/tree/multisig-simulation-kova-ovm-test DebtCache OVM instance: https://github.com/Synthetixio/synthetix/tree/debCache-l2 Note: the initial measurements show that DebtCache's `takeDebtSnapshot() is the real bottleneck.

`Dev Tasks:

  • [x] Report gas costs: L2 (RealtimeDebtCache) for exchanging in Mainnet-ovm, Kovan-ovm(more synths) and Kovan-ovm-test (less synths).

Realtime Debt Cache 3 synths (sUSD, sETH, sBTC) - no fee reclamation gas-used: sUSD-sBTC gasUsed: 5,947,547 gas-used: sBTC-sETH gasUsed: 5,028,973 gas-used: sUSD-sETH gasUsed: 4,509,600

4 synths (sUSD, sETH, sBTC, sLINK) - no fee reclamation gas-used: sUSD-sLINK gasUsed: 5,947,601 gas-used: sUSD-sBTC gasUsed: 4,520,061 gas-used: sLINK-sETH gasUsed: 5,028,967

5 synths (sUSD, sETH, sBTC, sLINK, sUNI) - no fee reclamation gas-used: sUSD-sUNI gasUsed: 5,947,589 gas-used: sUNI-sBTC gasUsed: 5,039,394 gas-used: sUSD-sUNI gasUsed: 4,509,606 gas-used: sUNI-sLINK gasUsed: 5,039,454

6 synths (sUSD, sETH, sBTC, sLINK, sUNI, sAAVE) - no fee reclamation gas-used: sBTC-sAAVE gasUsed: 6,466,904 gas-used: sLINK-sAAVE gasUsed: 5,039,446 gas-used: sUSD-sBTC gasUsed: 4,509,624

6 synths (sUSD, sETH, sBTC, sLINK, sUNI, sAAVE) - no fee reclamation gas-used: sUSD-sRUNE gasUsed: 5,947,575 gas-used: sRUNE-sLINK gasUsed: 5,039,442

13 synths (sUSD, sETH, sBTC, sLINK, sUNI, sAAVE...) - no fee reclamation gas-used: sBTC-sREN gasUsed: 6,466,904 gas-used: sLINK-sXMR gasUsed: 6,466,962 gas-used: sXMR -sREN gasUsed: 5,039,468

  • [x] Hand over measurements to Kevin for feedback.
  • [x] Add DebtCache support on L2 and make new measurements.

Debt Cache 2 synths (sUSD, sETH) - no fee reclamation gas-used: sUSD-sETH gasUsed: 6,642,322 gas-used: sUSD-sETH gasUsed: 5,024,044

3 synths (sUSD, sETH, sBTC) - no fee reclamation gas-used: sUSD-sBTC gasUsed: 6,409,677 gas-used: sUSD-sBTC gasUsed: 4,971,740 gas-used: sBTC-sETH gasUsed: 5,691,923 gas-used: sUSD-sETH gasUsed: 5,024,062

6 synths (sUSD, sETH, sBTC, sLINK) - no fee reclamation snapshot: gas used: 3,457,216 gas-used: sUSD-sLINK gasUsed: 6,409,753 gas-used: sUSD-sUNI gasUsed: 6,409,699 gas-used: sUNI-sAAVE gasUsed: 7,067,120 gas-used: sBTC-sAAVE gasUsed: 5,650,095 gas-used: sUNI-sAAVE gasUsed: 5,650,089

9 synths (sUSD, sETH, sBTC, sLINK) - no fee reclamation snapshot: gas used: 4,874,795 gas-used: sLINK-sYFI gasUsed: 7,077,557 gas-used: sYFI-sSUSHI gasUsed: 7,077,563 gas-used: sYFI-sSUSHI gasUsed: 7,077,563 gas-used: sSUSHI-sYFI gasUsed: 5,650,101

12 synths (sUSD, sETH, sBTC, sLINK) - no fee reclamation snapshot: gas used: 6,153,165 gas-used: sBTC-sBAL gasUsed: 7,077,581 gas-used: sBAL-sDOT gasUsed: 7,077,563 gas-used: sBAL-sDOT gasUsed: 4,982,203 gas-used: sUSD-sBTC gasUsed: 4,982,203

i-stam avatar Mar 31 '21 15:03 i-stam

This is great! Thanks @i-stam

So, what can we read from these measurements? I'll list a few that come to my mind immediately. Perhaps we can later validate/falsify them on a discussion:

  1. With realtime debt cache, gas is high, but it doesn't grow that fast.
  2. I can't see a much of a gas improvement with debt caching enabled. Even feels a little worse, which is a bit counterintuitive.
  3. What does increase very quickly is the call to take the snapshot. Why?

eternauta1337 avatar Apr 09 '21 20:04 eternauta1337