near / nearcore

Reference client for NEAR Protocol
https://near.org
GNU General Public License v3.0
2.3k stars 613 forks source link

Update "Write Memory" Cost Estimation #8244

Open jakmeier opened 1 year ago

jakmeier commented 1 year ago

Our gas cost estimations for writing memory were designed before the optimization in https://github.com/near/nearcore/pull/8224. Before vs after the change also showed a significant change in costs in our daily qemu estimation.

It seems that only WriteMemoryByte was really affected by it.

// qemu
WriteMemoryByte           51_180 gas [0.41i 0.00r 0.00w]     ->      25_712 gas [0.21i 0.00r 0.00w]
// time
WriteMemoryByte          145_589 gas [145ps]                 ->      57_458 gas [57ps]

Here are the most similar costs, with basically no changes:

Qemu

ReadMemoryBase       197_467_681 gas [1579.74i 0.00r 0.00w]  -> 199_797_384 gas [1598.38i 0.00r 0.00w]
ReadMemoryByte            39_403 gas [0.32i 0.00r 0.00w]     ->      39_410 gas [0.32i 0.00r 0.00w]
WriteMemoryBase      252_254_835 gas [2018.04i 0.00r 0.00w]  -> 233_768_588 gas [1870.15i 0.00r 0.00w]
ReadRegisterBase     182_955_788 gas [1463.65i 0.00r 0.00w]  -> 186_395_669 gas [1491.17i 0.00r 0.00w] 
ReadRegisterByte          25_731 gas [0.21i 0.00r 0.00w]     ->      25_742 gas [0.21i 0.00r 0.00w]
WriteRegisterBase    285_342_844 gas [2282.74i 0.00r 0.00w]  -> 286_190_438 gas [2289.52i 0.00r 0.00w]
WriteRegisterByte         39_488 gas [0.32i 0.00r 0.00w]     ->      39_493 gas [0.32i 0.00r 0.00w]

Time (just fro completeness, these numbers have a high variation and cannot be trusted too much)

ReadMemoryBase      219_074_560 gas [219ns]   ->     215_235_022 gas [215ns]
ReadMemoryByte           97_582 gas [97ps]    ->          98_297 gas [98ps]
WriteMemoryBase     225_006_414 gas [225ns]   ->     211_035_132 gas [211ns] 
ReadRegisterBase    161_679_156 gas [162ns]   ->     205_708_607 gas [206ns]
ReadRegisterByte         62_532 gas [62ps]    ->          58_664 gas [58ps]
WriteRegisterBase   283_162_954 gas [283ns]   ->     309_679_023 gas [310ns]
WriteRegisterByte        99_406 gas [99ps]    ->          95_510 gas [95ps] 

TODO

The estimation should be updated, as it no longer hits the worst case. See also this comment: https://github.com/near/nearcore/pull/8224#discussion_r1049678652

mina86 commented 1 year ago

FYI, memory cost estimations may be further affected by https://github.com/near/nearcore/pull/8276

jakmeier commented 1 year ago

CE was broken for a while, the changes we see since the last successful run look like they are due #8224 and #8276

Report

Status: Warn
Current commit: 523f195ac8775414d1f95602808fc5512ca6d91b
Compared to: 4f8a2b4314b08307a0bcb2f4cfa99bd774726ac1
Relative gas estimation changes above threshold: 10

ActionDeleteKey                                15.60 Ggas ➜       18.72 Ggas (+20.00%)
ActionDeployContractPerByte                   257.50 Mgas ➜      231.62 Mgas (-10.05%)
ActionFunctionCallBase                         11.16 Ggas ➜       12.96 Ggas (+16.16%)
ContractCompileBytes                          239.38 Mgas ➜      214.69 Mgas (-10.31%)
ContractCompileBytesV2                        233.14 Mgas ➜      208.18 Mgas (-10.71%)
DataReceiptCreationBase                        35.13 Ggas ➜       38.94 Ggas (+10.86%)
ReadMemoryBase                                198.06 Mgas ➜      166.75 Mgas (-15.81%)
ReadMemoryByte                                  39399 gas ➜        25711 gas (-34.74%)
WriteRegisterBase                             291.15 Mgas ➜      259.53 Mgas (-10.86%)
WriteRegisterByte                               39497 gas ➜        25783 gas (-34.72%)