Skip to content
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

Gas used and execution time measurement for the Move function #2031

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

steelgeek091
Copy link
Collaborator

The current gas statistics for running the transfer command are as follows:

gas_used: 910165, time_used 1 -> "rooch_framework::account_coin_store::can_auto_accept_coin"    
gas_used: 950158, time_used 1 -> "rooch_framework::account_coin_store::is_accept_coin"    
gas_used: 8754, time_used 0 -> "moveos_std::bcs::to_bytes"    
gas_used: 30871, time_used 0 -> "moveos_std::type_info::type_name"    
gas_used: 48950, time_used 0 -> "moveos_std::bcs::from_bytes"    
gas_used: 81248, time_used 0 -> "moveos_std::address::from_bytes"    
gas_used: 11903, time_used 0 -> "moveos_std::object::address_to_object_id"    
gas_used: 2635151, time_used 1 -> "moveos_std::object::account_named_object_id"    
gas_used: 2673687, time_used 1 -> "rooch_framework::account_coin_store::account_coin_store_id"    
gas_used: 14165, time_used 0 -> "moveos_std::object::parent_id"    
gas_used: 13403, time_used 0 -> "moveos_std::object::is_parent"    
gas_used: 60329, time_used 0 -> "moveos_std::object::contains_object_field_internal"    
gas_used: 145125, time_used 0 -> "moveos_std::object::exists_object_with_type"    
gas_used: 14165, time_used 0 -> "moveos_std::object::parent_id"    
gas_used: 13403, time_used 0 -> "moveos_std::object::is_parent"    
gas_used: 60329, time_used 0 -> "moveos_std::object::contains_object_field_internal"    
gas_used: 145125, time_used 0 -> "moveos_std::object::exists_object_with_type"    
gas_used: 14165, time_used 0 -> "moveos_std::object::parent_id"    
gas_used: 13403, time_used 0 -> "moveos_std::object::is_parent"    
gas_used: 9323, time_used 0 -> "moveos_std::object::is_frozen_internal"    
gas_used: 106172, time_used 0 -> "moveos_std::object::borrow_mut_object_field_internal"    
gas_used: 191096, time_used 0 -> "moveos_std::object::borrow_mut_from_global"    
gas_used: 7608, time_used 0 -> "moveos_std::object::as_mut_ref"    
gas_used: 267502, time_used 0 -> "moveos_std::object::borrow_mut_object_internal"    
gas_used: 303529, time_used 0 -> "moveos_std::object::borrow_mut_object_extend"    
gas_used: 523633, time_used 0 -> "rooch_framework::coin_store::borrow_mut_coin_store_internal"    
gas_used: 3459720, time_used 1 -> "rooch_framework::account_coin_store::create_or_borrow_mut_account_coin_store"    
gas_used: 4488935, time_used 2 -> "rooch_framework::account_coin_store::deposit_internal"    
gas_used: 1174, time_used 0 -> "moveos_std::object::id"    
gas_used: 14165, time_used 1 -> "moveos_std::object::parent_id"    
gas_used: 13403, time_used 0 -> "moveos_std::object::is_parent"    
gas_used: 9323, time_used 0 -> "moveos_std::object::is_frozen_internal"    
gas_used: 106172, time_used 0 -> "moveos_std::object::borrow_mut_object_field_internal"    
gas_used: 191096, time_used 1 -> "moveos_std::object::borrow_mut_from_global"    
gas_used: 228592, time_used 1 -> "moveos_std::object::borrow_mut"    
gas_used: 5400, time_used 0 -> "rooch_framework::coin_store::check_coin_store_not_frozen"    
gas_used: 934, time_used 0 -> "rooch_framework::coin::value"    
gas_used: 41260, time_used 0 -> "rooch_framework::coin_store::merge_to_balance"    
gas_used: 29180, time_used 0 -> "moveos_std::type_info::type_name"    
gas_used: 3210, time_used 0 -> "moveos_std::event::emit"    
gas_used: 550067, time_used 1 -> "rooch_framework::coin_store::deposit_internal"    
gas_used: 9031177, time_used 5 -> "rooch_framework::account_coin_store::transfer_internal"    
gas_used: 9112407, time_used 5 -> "rooch_framework::account_coin_store::transfer"    

Additionally, since NativeContext is initialized each time a native function is called, a mechanism is needed to maintain gas statistics throughout the entire transaction execution process.

Copy link

vercel bot commented Jun 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rooch ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 4, 2024 4:35am
rooch-portal ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 4, 2024 4:35am


fn inject_parameter(
_gas_params: &MeasurementGas,
context: &mut NativeContext,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NativeContext is initialized each time a native function is called, a mechanism is needed to maintain gas statistics throughout the entire transaction execution process.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom a Native context like NativeEventContext or ObjectRuntimeContext

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom a Native context like NativeEventContext or ObjectRuntimeContext

OK, got it.

@baichuan3
Copy link
Collaborator

gas_used: 9112407, time_used 5 -> "rooch_framework::account_coin_store::transfer"  

看上去,除了transfer gas 非常高外,以下几个方法的 gas 也有些高的不合理

gas_used: 2635151, time_used 1 -> "moveos_std::object::account_named_object_id" 
gas_used: 2673687, time_used 1 -> "rooch_framework::account_coin_store::account_coin_store_id"  
gas_used: 3459720, time_used 1 -> "rooch_framework::account_coin_store::create_or_borrow_mut_account_coin_store"  

@steelgeek091
Copy link
Collaborator Author

gas_used: 9112407, time_used 5 -> "rooch_framework::account_coin_store::transfer"  

看上去,除了transfer gas 非常高外,以下几个方法的 gas 也有些高的不合理

gas_used: 2635151, time_used 1 -> "moveos_std::object::account_named_object_id" 
gas_used: 2673687, time_used 1 -> "rooch_framework::account_coin_store::account_coin_store_id"  
gas_used: 3459720, time_used 1 -> "rooch_framework::account_coin_store::create_or_borrow_mut_account_coin_store"  

这个也挺高

gas_used: 4488935, time_used 2 -> "rooch_framework::account_coin_store::deposit_internal"

@jolestar
Copy link
Contributor

account_named_object_id 因为要算一次 hash,感觉这个可以提前算好,然后定义成常量。

@jolestar
Copy link
Contributor

感觉这个方法的代码侵入性有点强,感觉可以通过 rust 的 feature 来控制,可以参照:

  1. https://github.com/move-language/move/blob/aptos-main/language/move-vm/runtime/src/debug.rs
  2. https://github.com/move-language/move/blob/aptos-main/language/move-vm/runtime/src/tracing.rs

然后 measurements.move 可以放在 rooch-nursery framework 中,这样就不会包含在主网的 framework 中。

@steelgeek091
Copy link
Collaborator Author

感觉这个方法的代码侵入性有点强,感觉可以通过 rust 的 feature 来控制,可以参照:

  1. https://github.com/move-language/move/blob/aptos-main/language/move-vm/runtime/src/debug.rs
  2. https://github.com/move-language/move/blob/aptos-main/language/move-vm/runtime/src/tracing.rs

然后 measurements.move 可以放在 rooch-nursery framework 中,这样就不会包含在主网的 framework 中。

好,我修改一下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants