-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
function_call_cost number cannot be explained #3094
Comments
Right now when a contract code is pulled from the trie without cache we rehash it to verify the hash matches the hash given in the account structure. In particular these 2 lines: and Cost of hashing 200Kb of data according to our math estimator is I suggest remove hashing of the contract code completely, since hash from the account ID + trie merkalization should be enough to enforce the code hash matches the code from the Trie. Also this The hash should be only verified during deploy action, which is already the case. |
Also it might be not hashing alone. Just reading 200Kb from the trie costs |
I think the best way to measure cost of compilation is to run a function call block with cache on (warmed up) and a block with cache off. The difference is the cost of cold compilation. |
FYI singlepass is JIT, so cache helps a little bit but not much. |
We also cache EDIT: I'll run a test with 2Mib memory limit instead. I think most Rust contract by default set stack start at 1Mib, so we shouldn't limit to 1Mib. Previous default limit was 33 pages. |
That's a lot :) |
Don't re-hash a contract code after a read if the `code_hash` is already available in the account ID. The only place to rehash is when `apply_genesis_records` is called. Ref: #3094 ## Test plan: - [x] CI - [x] Run fee estimator again. To compare. **this PR** ```rust data_receipt_creation_config: DataReceiptCreationConfig { base_cost: Fee { send_sir: 1035057529250, send_not_sir: 1035057529250, execution: 1035057529250, }, cost_per_byte: Fee { send_sir: 23636040, send_not_sir: 23636040, execution: 23636040, }, }, ``` vs ```rust data_receipt_creation_config: DataReceiptCreationConfig { base_cost: Fee { send_sir: 4697339419375, send_not_sir: 4697339419375, execution: 4697339419375, }, cost_per_byte: Fee { send_sir: 59357464, send_not_sir: 59357464, execution: 59357464, }, }, ``` **this PR** ```rust function_call_cost: Fee { send_sir: 1185240500000, send_not_sir: 1185240500000, execution: 1185240500000, }, function_call_cost_per_byte: Fee { send_sir: 1158368, send_not_sir: 1158368, execution: 1158368, }, ``` vs ```rust function_call_cost: Fee { send_sir: 2319861500000, send_not_sir: 2319861500000, execution: 2319861500000, }, function_call_cost_per_byte: Fee { send_sir: 2235934, send_not_sir: 2235934, execution: 2235934, }, ```
As mentioned in #3041 (comment) we do need proper definition of what meaning we expect from every individual fee, especially actions ones. Definition better be present in form of probes, inserted in proper places of the estimator code. @nearmax @evgenykuzyakov could you please cooperate here? |
Superseded by #4401 |
function_call_cost
is currently2319861500000
gas, see: https://github.com/nearprotocol/nearcore/blob/master/neard/res/genesis_config.json#L74This is the major limiting factor that restricts contract call TPS to 200. Initially we thought it is so large because the fee computation accidentally adds it to it the cost of trie update, Wasm compilation and loading, receipt creation for refunds, etc. However:
216750*100*2^10+35445963
which 100 times cheaper than the function call fee;108059500000
which is 21 times cheaper;64196736000
which is 36 times cheaper.There are no good explanations of where this cost is coming from. It might be an indication of a bug in params estimator or large sub-optimality in the runtime. We need to investigate this issue, especially since it can be an easy way to bump our TPS.
The text was updated successfully, but these errors were encountered: