omgnetwork / research

43 stars 2 forks source link

Abstract Layer POC: get metrics and documents them #94

Closed boolafish closed 5 years ago

boolafish commented 5 years ago

Main story of this originally wanted to compare the POC with current MoreVP implementation on gas cost. However, as the prototype is really nor securely implemented and mainly focused on has something rough to display the idea, it doesn't work to compare directly IMHO.

Would just collect some data of the gas cost of extra actions from the communications of different layers:

  1. Cost of proxy commands to ExitGame/ExitProcessor instead of using it directly.
  2. Cost of ExitGame/ExitProcessor to encode and store a struct data in PlasmaFramework.
  3. Cost of ExitGame/ExitProcessor to read and decode a struct data in PlasmaFramework.
  4. Compare the cost of using ABIEncoderV2 and not using that.
boolafish commented 5 years ago

Wrote a quick test in my own branch to get the numbers:

So App is the second layer on top of Framework. App would mimic the ExitGame and ExitProcessor.

All the results are saving and getting data with the following structure:

struct Data {
        uint256 exitId;
        uint8 exitType;
        bool exitable;
        bytes32 outputHash;
        address token;
        address exitTarget;
        uint256 amount;
}

Following is what dumps from my terminal, will see the gas cost first and then the description of the execution. The difference of the "Total gas used" and "Execution gas" is a basic call to a dummy function in framework layer.

  Contract: AppAbiV2
    Using struct data and ABIEncoderV2
-----
Total gas used: 191277
Execution gas: 169872
      ✓ save struct data to framework storage for the first time (93ms)
-----
Total gas used: 71277
Execution gas: 49872
      ✓ save same struct data to the same slot the second time (176ms)
-----
Total gas used: 56299
Execution gas: 34894
      ✓ save struct data with different flag to the same slot (121ms)
-----
Total gas used: 33540
Execution gas: 12135
      ✓ get struct data from framework storage (112ms)
-----
Total gas used: 25672
Execution gas: 4267
      ✓ proxies from framework to app (41ms)

  Contract: APP
    Using native data without ABIEncoderV2
-----
Total gas used: 190158
Execution gas: 168753
      ✓ save data to framework storage for the first time (56ms)
-----
Total gas used: 70158
Execution gas: 48753
      ✓ save same data to the same slot the second time (90ms)
-----
Total gas used: 55092
Execution gas: 33687
      ✓ save data with different flag to the same slot (91ms)
-----
Total gas used: 30384
Execution gas: 8979
      ✓ get data from framework storage (81ms)
-----
Total gas used: 25650
Execution gas: 4245
      ✓ proxies from framework to app
boolafish commented 5 years ago
  1. The extra gas cost for saving with ABIEncoderV2 is around 1000.
  2. The extra gas cost for getting with ABIEncoderV2 is around 3000.
  3. Proxy itself costs around 4200
  4. What's inside "data" itself actually matters a lot to gas cost. In the test case "with different flag to same slot" it is cheaper then "save same data to the same slot". I am guessing this is because the flag is changed from true to false, and it does not take space for false as a data in struct, so it is optimized.
boolafish commented 5 years ago

linked to the parent story and to doc. closing this.