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

[move-stdlib] Use vector::move_range inside vector, and evaluate performance / calibrate gas #14862

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions aptos-move/aptos-gas-calibration/src/measurements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,17 @@ fn compile_and_run_samples_ir(
.equation_names
.push(format!("{}::{}", &identifier, func_identifier.0));

let elapsed = executor.exec_func_record_running_time(
&module_id,
&func_identifier.0,
vec![],
func_identifier.1.clone(),
iterations,
ExecFuncTimerDynamicArgs::NoArgs,
GasMeterType::UnmeteredGasMeter,
);
let elapsed = executor
.exec_func_record_running_time(
&module_id,
&func_identifier.0,
vec![],
func_identifier.1.clone(),
iterations,
ExecFuncTimerDynamicArgs::NoArgs,
GasMeterType::UnmeteredGasMeter,
)
.elapsed_micros;
gas_measurement.regular_meter.push(elapsed);

// record with abstract gas meter
Expand Down
20 changes: 11 additions & 9 deletions aptos-move/aptos-gas-calibration/src/measurements_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,17 @@ pub fn execute_user_txn(
iterations: u64,
args: Vec<Vec<u8>>,
) -> u128 {
let elapsed = executor.exec_func_record_running_time(
module_name,
function_name,
vec![],
args,
iterations,
ExecFuncTimerDynamicArgs::NoArgs,
GasMeterType::UnmeteredGasMeter,
);
let elapsed = executor
.exec_func_record_running_time(
module_name,
function_name,
vec![],
args,
iterations,
ExecFuncTimerDynamicArgs::NoArgs,
GasMeterType::UnmeteredGasMeter,
)
.elapsed_micros;
println!("running time (microseconds): {}", elapsed);
elapsed
}
Expand Down
20 changes: 18 additions & 2 deletions aptos-move/aptos-gas-schedule/src/gas_schedule/move_stdlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@

//! This module defines the gas parameters for Move Stdlib.

use crate::{gas_feature_versions::RELEASE_V1_18, gas_schedule::NativeGasParameters};
use aptos_gas_algebra::{InternalGas, InternalGasPerByte};
use crate::{
gas_feature_versions::{RELEASE_V1_18, RELEASE_V1_24},
gas_schedule::NativeGasParameters,
};
use aptos_gas_algebra::{
InternalGas, InternalGasPerAbstractValueUnit, InternalGasPerArg, InternalGasPerByte,
InternalGasPerTypeNode,
};

crate::gas_schedule::macros::define_gas_parameters!(
MoveStdlibGasParameters,
Expand Down Expand Up @@ -36,5 +42,15 @@ crate::gas_schedule::macros::define_gas_parameters!(
[bcs_serialized_size_base: InternalGas, { RELEASE_V1_18.. => "bcs.serialized_size.base" }, 735],
[bcs_serialized_size_per_byte_serialized: InternalGasPerByte, { RELEASE_V1_18.. => "bcs.serialized_size.per_byte_serialized" }, 36],
[bcs_serialized_size_failure: InternalGas, { RELEASE_V1_18.. => "bcs.serialized_size.failure" }, 3676],
[bcs_constant_serialized_size_base: InternalGas, { RELEASE_V1_24.. => "bcs.constant_serialized_size.base" }, 735],
[bcs_constant_serialized_size_per_type_node: InternalGasPerTypeNode, { RELEASE_V1_24.. => "bcs.constant_serialized_size.per_type_node" }, 40],

[mem_swap_base: InternalGas, { RELEASE_V1_24.. => "mem.swap.base" }, 1500],

[vector_move_range_base: InternalGas, { RELEASE_V1_24.. => "vector.move_range.base" }, 4000],
[vector_move_range_per_index_moved: InternalGasPerArg, { RELEASE_V1_24.. => "vector.move_range.per_index_moved" }, 10],

[cmp_compare_base: InternalGas, { RELEASE_V1_24.. => "cmp.compare.base" }, 367],
[cmp_compare_per_abs_val_unit: InternalGasPerAbstractValueUnit, { RELEASE_V1_24.. => "cmp.compare.per_abs_val_unit"}, 14],
]
);
2 changes: 1 addition & 1 deletion aptos-move/aptos-gas-schedule/src/ver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
/// global operations.
/// - V1
/// - TBA
pub const LATEST_GAS_FEATURE_VERSION: u64 = gas_feature_versions::RELEASE_V1_23;
pub const LATEST_GAS_FEATURE_VERSION: u64 = gas_feature_versions::RELEASE_V1_24;

pub mod gas_feature_versions {
pub const RELEASE_V1_8: u64 = 11;
Expand Down
7 changes: 7 additions & 0 deletions aptos-move/aptos-native-interface/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ impl<'a, 'b, 'c, 'd> SafeNativeContext<'a, 'b, 'c, 'd> {
.abstract_value_size(val, self.gas_feature_version)
}

/// Computes the abstract size of the input value.
pub fn abs_val_size_dereferenced(&self, val: &Value) -> AbstractValueSize {
self.misc_gas_params
.abs_val
.abstract_value_size_dereferenced(val, self.gas_feature_version)
}

/// Returns the current gas feature version.
pub fn gas_feature_version(&self) -> u64 {
self.gas_feature_version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub enum FeatureFlag {
TransactionSimulationEnhancement,
CollectionOwner,
EnableLoaderV2,
NativeMemoryOperations,
}

fn generate_features_blob(writer: &CodeWriter, data: &[u64]) {
Expand Down Expand Up @@ -349,6 +350,7 @@ impl From<FeatureFlag> for AptosFeatureFlag {
},
FeatureFlag::CollectionOwner => AptosFeatureFlag::COLLECTION_OWNER,
FeatureFlag::EnableLoaderV2 => AptosFeatureFlag::ENABLE_LOADER_V2,
FeatureFlag::NativeMemoryOperations => AptosFeatureFlag::NATIVE_MEMORY_OPERATIONS,
}
}
}
Expand Down Expand Up @@ -493,6 +495,7 @@ impl From<AptosFeatureFlag> for FeatureFlag {
},
AptosFeatureFlag::COLLECTION_OWNER => FeatureFlag::CollectionOwner,
AptosFeatureFlag::ENABLE_LOADER_V2 => FeatureFlag::EnableLoaderV2,
AptosFeatureFlag::NATIVE_MEMORY_OPERATIONS => FeatureFlag::NativeMemoryOperations,
}
}
}
Expand Down
20 changes: 11 additions & 9 deletions aptos-move/aptos-vm-benchmarks/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ pub fn execute_module_txn(

// sign user transaction and only records the body of the transaction
pub fn execute_user_txn(executor: &mut FakeExecutor, module_name: &ModuleId, function_name: &str) {
let elapsed = executor.exec_func_record_running_time(
module_name,
function_name,
vec![],
vec![],
10,
ExecFuncTimerDynamicArgs::NoArgs,
GasMeterType::UnmeteredGasMeter,
);
let elapsed = executor
.exec_func_record_running_time(
module_name,
function_name,
vec![],
vec![],
10,
ExecFuncTimerDynamicArgs::NoArgs,
GasMeterType::UnmeteredGasMeter,
)
.elapsed_micros;
println!("running time (microseconds): {}", elapsed);
}

Expand Down
21 changes: 20 additions & 1 deletion aptos-move/aptos-vm-environment/src/natives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,35 @@
use aptos_native_interface::SafeNativeBuilder;
use move_core_types::language_storage::CORE_CODE_ADDRESS;
use move_vm_runtime::native_functions::NativeFunctionTable;
use std::collections::HashSet;

/// Builds and returns all Aptos native functions.
pub fn aptos_natives_with_builder(
builder: &mut SafeNativeBuilder,
inject_create_signer_for_gov_sim: bool,
) -> NativeFunctionTable {
let vector_bytecode_instruction_methods = HashSet::from([
"empty",
"length",
"borrow",
"borrow_mut",
"push_back",
"pop_back",
"destroy_empty",
"swap",
]);

#[allow(unreachable_code)]
aptos_move_stdlib::natives::all_natives(CORE_CODE_ADDRESS, builder)
.into_iter()
.filter(|(_, name, _, _)| name.as_str() != "vector")
.filter(|(_, name, func_name, _)|
if name.as_str() == "vector" && vector_bytecode_instruction_methods.contains(func_name.as_str()) {
println!("ERROR: Tried to register as native a vector bytecode_instruction method {}, skipping.", func_name.as_str());
false
} else {
true
}
)
.chain(aptos_framework::natives::all_natives(
CORE_CODE_ADDRESS,
builder,
Expand Down
Loading
Loading