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

feat: add gas-cost-bundles asset for benchmark improvement #193

Merged
merged 1 commit into from
May 24, 2024
Merged
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
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,3 @@ gas_costs.txt

# Move Build Output
build/

Calibration.move
gen_smove_instr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bundle*
32 changes: 32 additions & 0 deletions pallet/src/assets/move-projects/gas-costs-bundles/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh
cd $(dirname $0)

ITERATIONS=25

function write_module() {
printf "module AiBob::CalMod$2 {\n" >> $1
printf " fun fun_fun(a: u8) {\n" >> $1
printf " assert!(a == 0, 0);\n" >> $1
printf " }\n" >> $1
printf "}\n" >> $1
}

function create_move_project() {
NAME=bundle$1
smove new $NAME
TOML=$NAME/Move.toml
printf 'AiBob = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"' >> $TOML
for i in $(seq 1 $1)
do
FILE=$NAME/sources/Modules.move
write_module $FILE $i
done
sync
smove bundle -p $NAME
}

rm -rf bundle*
for i in $(seq 1 $ITERATIONS)
do
create_move_project $i
done
2 changes: 2 additions & 0 deletions pallet/src/assets/move-projects/gas-costs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gen_smove_instr.sh
Calibration.move
130 changes: 69 additions & 61 deletions pallet/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ macro_rules! impl_gas_costs_cal_fns {
};
}

macro_rules! impl_gas_costs_cal_bundles {
($name:tt) => {
pub fn $name() -> &'static [u8] {
core::include_bytes!(concat!(
"assets/move-projects/gas-costs-bundles/",
stringify!($name),
"/build/",
stringify!($name),
"/bundles/",
stringify!($name),
".mvb"
))
}
};
}

#[benchmarks(
where
T: Config + SysConfig,
Expand Down Expand Up @@ -94,40 +110,42 @@ mod benchmarks {
}

#[benchmark]
fn publish_module(n: Linear<0, 2>) {
let bob_32 = utils::account::<T>(utils::BOB_ADDR);

let module_bcs = [
multiple_signers_module().to_vec(),
car_wash_example_module().to_vec(),
base58_smove_build_module().to_vec(),
];
let gas = [661, 732, 100];

#[extrinsic_call]
publish_module(
RawOrigin::Signed(bob_32),
module_bcs[n as usize].clone(),
gas[n as usize],
);
}

#[benchmark]
fn publish_module_bundle(n: Linear<0, 2>) {
fn publish_module_generic(n: Linear<0, 24>) {
let bob_32 = utils::account::<T>(utils::BOB_ADDR);

let bundles = [
multiple_signers_module_as_bundle().to_vec(),
car_wash_example_module_as_bundle().to_vec(),
base58_smove_build_module_as_bundle().to_vec(),
bundle1().to_vec(),
bundle2().to_vec(),
bundle3().to_vec(),
bundle4().to_vec(),
bundle5().to_vec(),
bundle6().to_vec(),
bundle7().to_vec(),
bundle8().to_vec(),
bundle9().to_vec(),
bundle10().to_vec(),
bundle11().to_vec(),
bundle12().to_vec(),
bundle13().to_vec(),
bundle14().to_vec(),
bundle15().to_vec(),
bundle16().to_vec(),
bundle17().to_vec(),
bundle18().to_vec(),
bundle19().to_vec(),
bundle20().to_vec(),
bundle21().to_vec(),
bundle22().to_vec(),
bundle23().to_vec(),
bundle24().to_vec(),
bundle25().to_vec(),
];
let gas = [664, 735, 102];

#[extrinsic_call]
publish_module_bundle(
RawOrigin::Signed(bob_32),
bundles[n as usize].clone(),
gas[n as usize],
(n + 1) * 114,
);
}

Expand Down Expand Up @@ -169,42 +187,6 @@ mod benchmarks {
use benchmark_only::*;

mod benchmark_only {
// Base58 build example
pub fn base58_smove_build_module() -> &'static [u8] {
core::include_bytes!(
"assets/move-projects/base58_smove_build/build/base58_smove_build/bytecode_modules/BobBase58.mv"
)
}
pub fn base58_smove_build_module_as_bundle() -> &'static [u8] {
core::include_bytes!(
"assets/move-projects/base58_smove_build/build/base58_smove_build/bundles/base58_smove_build.mvb"
)
}

// Car Wash Example
pub fn car_wash_example_module() -> &'static [u8] {
core::include_bytes!(
"assets/move-projects/car-wash-example/build/car-wash-example/bytecode_modules/CarWash.mv"
)
}
pub fn car_wash_example_module_as_bundle() -> &'static [u8] {
core::include_bytes!(
"assets/move-projects/car-wash-example/build/car-wash-example/bundles/car-wash-example.mvb"
)
}

// Multiple Signers Example
pub fn multiple_signers_module() -> &'static [u8] {
core::include_bytes!(
"assets/move-projects/multiple-signers/build/multiple-signers/bytecode_modules/Dorm.mv"
)
}
pub fn multiple_signers_module_as_bundle() -> &'static [u8] {
core::include_bytes!(
"assets/move-projects/multiple-signers/build/multiple-signers/bundles/multiple-signers.mvb"
)
}

// Basic Coin Example
pub fn publish_basic_coin() -> &'static [u8] {
core::include_bytes!(
Expand Down Expand Up @@ -243,4 +225,30 @@ mod benchmark_only {
impl_gas_costs_cal_fns!(mint_23);
impl_gas_costs_cal_fns!(mint_24);
impl_gas_costs_cal_fns!(mint_25);

impl_gas_costs_cal_bundles!(bundle1);
impl_gas_costs_cal_bundles!(bundle2);
impl_gas_costs_cal_bundles!(bundle3);
impl_gas_costs_cal_bundles!(bundle4);
impl_gas_costs_cal_bundles!(bundle5);
impl_gas_costs_cal_bundles!(bundle6);
impl_gas_costs_cal_bundles!(bundle7);
impl_gas_costs_cal_bundles!(bundle8);
impl_gas_costs_cal_bundles!(bundle9);
impl_gas_costs_cal_bundles!(bundle10);
impl_gas_costs_cal_bundles!(bundle11);
impl_gas_costs_cal_bundles!(bundle12);
impl_gas_costs_cal_bundles!(bundle13);
impl_gas_costs_cal_bundles!(bundle14);
impl_gas_costs_cal_bundles!(bundle15);
impl_gas_costs_cal_bundles!(bundle16);
impl_gas_costs_cal_bundles!(bundle17);
impl_gas_costs_cal_bundles!(bundle18);
impl_gas_costs_cal_bundles!(bundle19);
impl_gas_costs_cal_bundles!(bundle20);
impl_gas_costs_cal_bundles!(bundle21);
impl_gas_costs_cal_bundles!(bundle22);
impl_gas_costs_cal_bundles!(bundle23);
impl_gas_costs_cal_bundles!(bundle24);
impl_gas_costs_cal_bundles!(bundle25);
}
15 changes: 9 additions & 6 deletions pallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ pub mod weight_info {
/// Weight functions needed for pallet_move.
pub trait WeightInfo {
fn execute(gas: u32) -> Weight;
fn publish_module(gas: u32) -> Weight;
fn publish_module_bundle(gas: u32) -> Weight;
// Both `publish_module` and `publish_module_bundle` share the same weight cost calculation
// since both functions are almost identical and should cost the same. More info:
// `publish_module` internally just invokes `publish_module_bundle` with a single-module
// bundle.
fn publish_module_generic(gas: u32) -> Weight;
Rqnsom marked this conversation as resolved.
Show resolved Hide resolved
fn update_stdlib_bundle() -> Weight;
}
}
Expand Down Expand Up @@ -350,7 +353,7 @@ pub mod pallet {
/// Publish a Move module sent by the user.
/// Module is published under its sender's address.
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::publish_module(*gas_limit))]
#[pallet::weight(T::WeightInfo::publish_module_generic(*gas_limit))]
pub fn publish_module(
origin: OriginFor<T>,
bytecode: Vec<u8>,
Expand Down Expand Up @@ -379,7 +382,7 @@ pub mod pallet {
///
/// Bundle is just a set of multiple modules.
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::publish_module_bundle(*gas_limit))]
#[pallet::weight(T::WeightInfo::publish_module_generic(*gas_limit))]
pub fn publish_module_bundle(
origin: OriginFor<T>,
bundle: Vec<u8>,
Expand Down Expand Up @@ -650,7 +653,7 @@ pub mod pallet {
Ok(MoveApiEstimation {
vm_status_code: vm_result.status_code.into(),
gas_used: vm_result.gas_used,
total_weight_including_gas_used: T::WeightInfo::publish_module(
total_weight_including_gas_used: T::WeightInfo::publish_module_generic(
vm_result.gas_used as u32,
),
})
Expand All @@ -666,7 +669,7 @@ pub mod pallet {
Ok(MoveApiEstimation {
vm_status_code: vm_result.status_code.into(),
gas_used: vm_result.gas_used,
total_weight_including_gas_used: T::WeightInfo::publish_module_bundle(
total_weight_including_gas_used: T::WeightInfo::publish_module_generic(
vm_result.gas_used as u32,
),
})
Expand Down
51 changes: 18 additions & 33 deletions pallet/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
//! Autogenerated weights for `pallet_move`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-05-23, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2024-05-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `bonka-MacBook-Pro.local`, CPU: `<UNKNOWN>`
//! HOSTNAME: `michaeleberhardts-MacBook-Pro.local`, CPU: `<UNKNOWN>`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024

// Executed Command:
Expand Down Expand Up @@ -49,42 +49,27 @@ impl<T: frame_system::Config> crate::weight_info::WeightInfo for SubstrateWeight
// Proof Size summary in bytes:
// Measured: `8622`
// Estimated: `17037`
// Minimum execution time: 345_000_000 picoseconds.
Weight::from_parts(348_832_865, 0)
// Minimum execution time: 346_000_000 picoseconds.
Weight::from_parts(348_557_924, 0)
.saturating_add(Weight::from_parts(0, 17037))
// Standard Error: 25_764
.saturating_add(Weight::from_parts(5_607_737, 0).saturating_mul(n.into()))
// Standard Error: 8_132
.saturating_add(Weight::from_parts(5_921_881, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(3))
}
/// Storage: `MoveModule::VMStorage` (r:1 w:1)
/// Proof: `MoveModule::VMStorage` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `n` is `[0, 2]`.
fn publish_module(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `7796`
// Estimated: `14073`
// Minimum execution time: 42_000_000 picoseconds.
Weight::from_parts(310_274_033, 0)
.saturating_add(Weight::from_parts(0, 14073))
// Standard Error: 3_569_607
.saturating_add(Weight::from_parts(4_038_397, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `MoveModule::VMStorage` (r:1 w:1)
/// Proof: `MoveModule::VMStorage` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `n` is `[0, 2]`.
fn publish_module_bundle(n: u32, ) -> Weight {
/// The range of component `n` is `[0, 24]`.
fn publish_module_generic(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `7796`
// Estimated: `14073`
// Minimum execution time: 43_000_000 picoseconds.
Weight::from_parts(311_709_392, 0)
.saturating_add(Weight::from_parts(0, 14073))
// Standard Error: 3_599_218
.saturating_add(Weight::from_parts(4_712_707, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(2))
// Measured: `111`
// Estimated: `3576`
// Minimum execution time: 56_000_000 picoseconds.
Weight::from_parts(54_952_033, 0)
.saturating_add(Weight::from_parts(0, 3576))
// Standard Error: 10_473
.saturating_add(Weight::from_parts(27_356_941, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `MoveModule::VMStorage` (r:1 w:1)
Expand All @@ -93,8 +78,8 @@ impl<T: frame_system::Config> crate::weight_info::WeightInfo for SubstrateWeight
// Proof Size summary in bytes:
// Measured: `7796`
// Estimated: `11261`
// Minimum execution time: 198_000_000 picoseconds.
Weight::from_parts(200_000_000, 0)
// Minimum execution time: 208_000_000 picoseconds.
Weight::from_parts(210_000_000, 0)
.saturating_add(Weight::from_parts(0, 11261))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
Expand Down
Loading