Skip to content

Commit

Permalink
[move][stdlib] Add vector::split_off and vector::remove library methods
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-aptos committed Nov 14, 2024
1 parent 2bb2d43 commit a10b5ae
Show file tree
Hide file tree
Showing 18 changed files with 1,026 additions and 167 deletions.
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: 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
191 changes: 169 additions & 22 deletions aptos-move/e2e-benchmark/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use aptos_language_e2e_tests::{
account::Account,
executor::{ExecFuncTimerDynamicArgs, FakeExecutor, GasMeterType},
executor::{ExecFuncTimerDynamicArgs, FakeExecutor, GasMeterType, TimeAndGas},
};
use aptos_transaction_generator_lib::{
publishing::{
Expand Down Expand Up @@ -46,7 +46,7 @@ fn execute_and_time_entry_point(
publisher_address: &AccountAddress,
executor: &mut FakeExecutor,
iterations: u64,
) -> u128 {
) -> TimeAndGas {
let mut rng = StdRng::seed_from_u64(14);
let entry_fun = entry_point
.create_payload(
Expand Down Expand Up @@ -102,6 +102,78 @@ TokenV1MintAndTransferNFTSequential 6 0.991 1.067 543.7
TokenV2AmbassadorMint { numbered: true } 6 0.987 1.052 474.4
LiquidityPoolSwap { is_stable: true } 6 0.970 1.042 555.4
LiquidityPoolSwap { is_stable: false } 6 0.925 1.001 535.3
(146, EntryPoints::CoinInitAndMint),
(154, EntryPoints::FungibleAssetMint),
(23, EntryPoints::IncGlobalMilestoneAggV2 {
milestone_every: 1,
}),
(12, EntryPoints::IncGlobalMilestoneAggV2 {
milestone_every: 2,
}),
(6871, EntryPoints::EmitEvents { count: 1000 }),
// long vectors with small elements
(15890, EntryPoints::VectorTrimAppend {
// baseline, only vector creation
vec_len: 3000,
element_len: 1,
index: 0,
repeats: 0,
}),
(38047, EntryPoints::VectorTrimAppend {
vec_len: 3000,
element_len: 1,
index: 100,
repeats: 1000,
}),
(25923, EntryPoints::VectorTrimAppend {
vec_len: 3000,
element_len: 1,
index: 2990,
repeats: 1000,
}),
(35590, EntryPoints::VectorRemoveInsert {
vec_len: 3000,
element_len: 1,
index: 100,
repeats: 1000,
}),
(28141, EntryPoints::VectorRemoveInsert {
vec_len: 3000,
element_len: 1,
index: 2998,
repeats: 1000,
}),
(53500, EntryPoints::VectorRangeMove {
vec_len: 3000,
element_len: 1,
index: 1000,
move_len: 500,
repeats: 1000,
}),
// vectors with large elements
(654, EntryPoints::VectorTrimAppend {
// baseline, only vector creation
vec_len: 100,
element_len: 100,
index: 0,
repeats: 0,
}),
(11147, EntryPoints::VectorTrimAppend {
vec_len: 100,
element_len: 100,
index: 10,
repeats: 1000,
}),
(5545, EntryPoints::VectorRangeMove {
vec_len: 100,
element_len: 100,
index: 50,
move_len: 10,
repeats: 1000,
}),
";

struct CalibrationInfo {
Expand Down Expand Up @@ -145,7 +217,7 @@ fn main() {
loop_type: LoopType::Arithmetic,
},
// This is a cheap bcs (serializing vec<u8>), so not representative of what BCS native call should cost.
// (, EntryPoints::Loop { loop_count: Some(1000), loop_type: LoopType::BCS { len: 1024 }}),
// (, EntryPoints::Loop { loop_count: Some(1000), loop_type: LoopType::BcsToBytes { len: 1024 }}),
EntryPoints::CreateObjects {
num_objects: 10,
object_payload_size: 0,
Expand All @@ -162,9 +234,9 @@ fn main() {
num_objects: 100,
object_payload_size: 10 * 1024,
},
EntryPoints::InitializeVectorPicture { length: 40 },
EntryPoints::VectorPicture { length: 40 },
EntryPoints::VectorPictureRead { length: 40 },
EntryPoints::InitializeVectorPicture { length: 128 },
EntryPoints::VectorPicture { length: 128 },
EntryPoints::VectorPictureRead { length: 128 },
EntryPoints::InitializeVectorPicture { length: 30 * 1024 },
EntryPoints::VectorPicture { length: 30 * 1024 },
EntryPoints::VectorPictureRead { length: 30 * 1024 },
Expand All @@ -187,14 +259,83 @@ fn main() {
EntryPoints::TokenV2AmbassadorMint { numbered: true },
EntryPoints::LiquidityPoolSwap { is_stable: true },
EntryPoints::LiquidityPoolSwap { is_stable: false },
EntryPoints::CoinInitAndMint,
EntryPoints::FungibleAssetMint,
EntryPoints::IncGlobalMilestoneAggV2 {
milestone_every: 1,
},
EntryPoints::IncGlobalMilestoneAggV2 {
milestone_every: 2,
},
EntryPoints::EmitEvents { count: 1000 },
// long vectors with small elements
EntryPoints::VectorSplitOffAppend {
// baseline, only vector creation
vec_len: 3000,
element_len: 1,
index: 0,
repeats: 0,
},
EntryPoints::VectorSplitOffAppend {
vec_len: 3000,
element_len: 1,
index: 100,
repeats: 1000,
},
EntryPoints::VectorSplitOffAppend {
vec_len: 3000,
element_len: 1,
index: 2990,
repeats: 1000,
},
EntryPoints::VectorRemoveInsert {
vec_len: 3000,
element_len: 1,
index: 100,
repeats: 1000,
},
EntryPoints::VectorRemoveInsert {
vec_len: 3000,
element_len: 1,
index: 2998,
repeats: 1000,
},
EntryPoints::VectorRangeMove {
vec_len: 3000,
element_len: 1,
index: 1000,
move_len: 500,
repeats: 1000,
},
// vectors with large elements
EntryPoints::VectorSplitOffAppend {
// baseline, only vector creation
vec_len: 100,
element_len: 100,
index: 0,
repeats: 0,
},
EntryPoints::VectorSplitOffAppend {
vec_len: 100,
element_len: 100,
index: 10,
repeats: 1000,
},
EntryPoints::VectorRangeMove {
vec_len: 100,
element_len: 100,
index: 50,
move_len: 10,
repeats: 1000,
},
];

let mut failures = Vec::new();
let mut json_lines = Vec::new();

println!(
"{:>15} {:>15} {:>15} entry point",
"wall time (us)", "expected (us)", "diff(- is impr)"
"{:>13} {:>13} {:>13}{:>13} {:>13} {:>13} entry point",
"walltime(us)", "expected(us)", "dif(- is impr)", "gas/s", "exe gas", "io gas",
);

for (index, entry_point) in entry_points.into_iter().enumerate() {
Expand All @@ -214,7 +355,6 @@ fn main() {
0,
package.publish_transaction_payload(),
);
println!("Published package: {:?}", entry_point.package_name());
if let Some(init_entry_point) = entry_point.initialize_entry_point() {
execute_txn(
&mut executor,
Expand All @@ -226,13 +366,9 @@ fn main() {
Some(publisher.address()),
),
);
println!(
"Executed init entry point: {:?}",
entry_point.initialize_entry_point()
);
}

let elapsed_micros = execute_and_time_entry_point(
let measurement = execute_and_time_entry_point(
&entry_point,
&package,
publisher.address(),
Expand All @@ -245,33 +381,44 @@ fn main() {
100
},
);
let diff = (elapsed_micros as f32 - expected_time) / expected_time * 100.0;
let diff = (measurement.elapsed_micros as f32 - expected_time as f32)
/ (expected_time as f32)
* 100.0;
println!(
"{:15} {:15.1} {:14.1}% {:?}",
elapsed_micros, expected_time, diff, entry_point
"{:13} {:13.1} {:12.1}% {:13} {:13} {:13} {:?}",
measurement.elapsed_micros,
expected_time,
diff,
(measurement.execution_gas + measurement.io_gas) as u128 / measurement.elapsed_micros,
measurement.execution_gas,
measurement.io_gas,
entry_point
);

json_lines.push(json!({
"grep": "grep_json_aptos_move_vm_perf",
"transaction_type": entry_point_name,
"wall_time_us": elapsed_micros,
"wall_time_us": measurement.elapsed_micros,
"gps": (measurement.execution_gas + measurement.io_gas) as u128 / measurement.elapsed_micros,
"execution_gas": measurement.execution_gas,
"io_gas": measurement.io_gas,
"expected_wall_time_us": expected_time,
"test_index": index,
}));

if elapsed_micros as f32
if measurement.elapsed_micros as f32
> expected_time as f32 * (1.0 + ALLOWED_REGRESSION) + ABSOLUTE_BUFFER_US
{
failures.push(format!(
"Performance regression detected: {}us, expected: {}us, diff: {}%, for {:?}",
elapsed_micros, expected_time, diff, entry_point
measurement.elapsed_micros, expected_time, diff, entry_point
));
} else if elapsed_micros as f32 + ABSOLUTE_BUFFER_US
} else if measurement.elapsed_micros as f32 + ABSOLUTE_BUFFER_US
< expected_time as f32 * (1.0 - ALLOWED_IMPROVEMENT)
{
failures.push(format!(
"Performance improvement detected: {}us, expected {}us, diff: {}%, for {:?}. You need to adjust expected time!",
elapsed_micros, expected_time, diff, entry_point
measurement.elapsed_micros, expected_time, diff, entry_point
));
}
}
Expand Down
Loading

0 comments on commit a10b5ae

Please sign in to comment.