-
Notifications
You must be signed in to change notification settings - Fork 686
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
True cost of function calls #7227
Comments
With all the changes around the estimator in the past two weeks, I was now able to estimate these "true" function call costs without instability or inaccuracy. I ran the tests on our estimator hardware setup on gcloud, with a state that is preloaded with 1M accounts and RocksDB stored on an SSD. I found that Here is the summary of what changes to parameters the estimator suggests:
* Might be reduced with flat storage These changes translate to per fn-call minimum overhead gas cost as follows, depending on contract code size.
|
cc @akhi3030 @bowenwang1996 @matklad @nagisa I don't think we can move forward with the plan to "ship the new fn base costs". Some re-prioritisation is probably required here. As the table above shows, we could keep total fn base costs for small contracts at around the same cost as today, but not decrease it. Even worse, we would have to increase costs for large contracts, e.g. Aurora would go from 5 Tgas currently to 40 Tgas afterwards. There are two main problems.
For number 1, we could prefetch DB reads for account data, access key data, and contract code. We have a potential of 4.1ms we could shave off this way, for all contracts regardless of size. This would make the smallest contracts up to 85% cheaper compared to today. For number 2, it's important to understand that estimation is based on a contract that adds more and more functions. This is a proxy for what we assume to be a close to worst-case contract for loading. |
There is quite a big reduction in |
Do we have a design already for prefetching contracts? |
Yeah, we know that we have been overcharging this part to cover undercharged costs in function loading. I'd say that was the main motivation behind looking all of these costs in combination and fixing the gas model first, before changing any single parameter.
Not that I am aware of. But it wouldn't be substantially different from accounts + access key prefetching, for which we have a Jira issue STR-4. |
we already store the size of the contract, so this should be "easy" to do I think diff --git a/core/store/src/lib.rs b/core/store/src/lib.rs
index eeeb4cf3e..e9b890f9b 100644
--- a/core/store/src/lib.rs
+++ b/core/store/src/lib.rs
@@ -555,8 +555,12 @@ pub fn get_code(
code_hash: Option<CryptoHash>,
) -> Result<Option<ContractCode>, StorageError> {
state_update
- .get(&TrieKey::ContractCode { account_id: account_id.clone() })
- .map(|opt| opt.map(|code| ContractCode::new(code, code_hash)))
+ .get_ref(&TrieKey::ContractCode { account_id: account_id.clone() })
+ .map(|opt| opt.map(|ptr| {
+ let l = ptr.len();
+ gas_counter.add(l * loading_cost_per_byte)?;
+ ContractCode::new(ptr.deref_value()?, code_hash)
+ }))
}
/// Removes account, code and all access keys associated to it. filed https://near.zulipchat.com/#narrow/stream/295306-pagoda.2Fcontract-runtime/topic/When.20to.20charge.20loading.20cost for discussing this |
Summary from the zulip thread + VC call between @matklad and @jakmeier 👍
|
I think
It's interesting that we don't flag this as uncertain, because we measure aggregate time there, rather than average. |
Pretty sure I was running 3 warm-up iterations and then 10 measured iterations, I suspect the warmup only makes a difference because you are running with caches enabled here. I was running without caches, a.k.a. But it's still an interesting finding, I would have thought pure loading costs are not affected by caches. I think we need to find out:
|
This reverts commit f7aca03. Reverting based on discussion at #7227 The TL;DR is while the current impl of the feature charges correct cost for contract loading at *logically* correct place, we'd want to move the charging a little bit earlier physically, even before we load the contract from the database, so that the cost can be lower without adding an extra protocol feature here.
It seems the numbers presented here for current "true costs" are mostly accurate. Closing this issue now. |
Measure the "true" cost of setting up a function call. This is about everything from processing the transaction all the way to persisting results. Excluded is the dynamic part, i.e. what happens inside the guest VM.
The model itself is discussed in #6992. This issue here is about finding the correct gas numbers for each parameter.
The text was updated successfully, but these errors were encountered: