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

dev: update vm initialization benchmark #1505

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
32 changes: 16 additions & 16 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fuel-core-tests = { version = "0.0.0", path = "./tests" }
fuel-core-xtask = { version = "0.0.0", path = "./xtask" }

# Fuel dependencies
fuel-vm-private = { version = "0.42.1", package = "fuel-vm", default-features = false }
fuel-vm-private = { version = "0.43.0", package = "fuel-vm", default-features = false }

# Common dependencies
anyhow = "1.0"
Expand Down
5 changes: 4 additions & 1 deletion benches/benches/block_target_gas_set/default_gas_costs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ pub fn default_gas_costs() -> GasCostsValues {
lw: 2,
mint: 25515,
mlog: 2,
vm_initialization: 1,
vm_initialization: DependentCost::HeavyOperation {
base: 2000,
gas_per_unit: 0,
},
modi: 2,
mod_op: 2,
movi: 2,
Expand Down
85 changes: 47 additions & 38 deletions benches/benches/vm_initialization.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use criterion::{
black_box,
Criterion,
Throughput,
};
use fuel_core_types::{
fuel_asm::{
Expand All @@ -17,8 +18,12 @@ use fuel_core_types::{
Transaction,
Word,
},
fuel_types::canonical::Serialize,
fuel_vm::{
checked_transaction::IntoChecked,
checked_transaction::{
Checked,
IntoChecked,
},
interpreter::NotSupportedEcal,
Interpreter,
},
Expand All @@ -29,11 +34,13 @@ use rand::{
SeedableRng,
};

pub fn vm_initialization(c: &mut Criterion) {
let rng = &mut StdRng::seed_from_u64(8586);
fn transaction<R: Rng>(
rng: &mut R,
script: Vec<u8>,
script_data: Vec<u8>,
) -> Checked<Script> {
let consensus_params = ConsensusParameters::default();

let inputs = (0..consensus_params.tx_params.max_inputs)
let inputs = (0..1)
.map(|_| {
Input::coin_predicate(
rng.gen(),
Expand All @@ -43,59 +50,61 @@ pub fn vm_initialization(c: &mut Criterion) {
rng.gen(),
rng.gen(),
0,
vec![
255;
(consensus_params.predicate_params.max_predicate_length
/ consensus_params.tx_params.max_inputs as u64)
as usize
],
vec![
255;
(consensus_params.predicate_params.max_predicate_data_length
/ consensus_params.tx_params.max_inputs as u64)
as usize
],
vec![255; 1],
vec![255; 1],
)
})
.collect();

let outputs = (0..consensus_params.tx_params.max_outputs)
let outputs = (0..1)
.map(|_| {
Output::variable(Default::default(), Default::default(), Default::default())
})
.collect();

let tx = Transaction::script(
1000000,
vec![
op::ret(1);
consensus_params.script_params.max_script_length as usize / Instruction::SIZE
]
.into_iter()
.collect(),
vec![255; consensus_params.script_params.max_script_data_length as usize],
Transaction::script(
1_000_000,
script,
script_data,
Policies::new()
.with_gas_price(0)
.with_maturity(0.into())
.with_max_fee(Word::MAX),
inputs,
outputs,
vec![vec![123; 100].into(); consensus_params.tx_params.max_witnesses as usize],
vec![vec![123; 32].into(); 1],
)
.into_checked_basic(Default::default(), &consensus_params)
.expect("Should produce a valid transaction");
.expect("Should produce a valid transaction")
}

pub fn vm_initialization(c: &mut Criterion) {
let mut rng = StdRng::seed_from_u64(8586);

let mut group = c.benchmark_group("vm_initialization");

group.bench_function("vm_initialization", |b| {
b.iter(|| {
let mut vm = black_box(
Interpreter::<_, Script, NotSupportedEcal>::with_memory_storage(),
);
black_box(vm.init_script(tx.clone()))
.expect("Should be able to execute transaction");
})
});
// Generate N data points
const N: usize = 18;
for i in 5..N {
let size = 8 * 1 << i;
let script = vec![op::ret(1); size / Instruction::SIZE]
.into_iter()
.collect();
let script_data = vec![255; size];
let tx = transaction(&mut rng, script, script_data);
let tx_size = tx.transaction().size();
let name = format!("vm_initialization_with_tx_size_{}", tx_size);
group.throughput(Throughput::Bytes(tx_size as u64));
group.bench_function(name, |b| {
b.iter(|| {
let mut vm = black_box(
Interpreter::<_, Script, NotSupportedEcal>::with_memory_storage(),
);
black_box(vm.init_script(tx.clone()))
.expect("Should be able to execute transaction");
})
});
}

group.finish();
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,12 @@ expression: json
}
},
"new_storage_per_byte": 1,
"vm_initialization": 2000
"vm_initialization": {
"HeavyOperation": {
"base": 2000,
"gas_per_unit": 0
}
}
},
"base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,12 @@ expression: json
}
},
"new_storage_per_byte": 1,
"vm_initialization": 2000
"vm_initialization": {
"HeavyOperation": {
"base": 2000,
"gas_per_unit": 0
}
}
},
"base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,12 @@ expression: json
}
},
"new_storage_per_byte": 1,
"vm_initialization": 2000
"vm_initialization": {
"HeavyOperation": {
"base": 2000,
"gas_per_unit": 0
}
}
},
"base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,12 @@ expression: json
}
},
"new_storage_per_byte": 1,
"vm_initialization": 2000
"vm_initialization": {
"HeavyOperation": {
"base": 2000,
"gas_per_unit": 0
}
}
},
"base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,12 @@ expression: json
}
},
"new_storage_per_byte": 1,
"vm_initialization": 2000
"vm_initialization": {
"HeavyOperation": {
"base": 2000,
"gas_per_unit": 0
}
}
},
"base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,12 @@ expression: json
}
},
"new_storage_per_byte": 1,
"vm_initialization": 2000
"vm_initialization": {
"HeavyOperation": {
"base": 2000,
"gas_per_unit": 0
}
}
},
"base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,12 @@ expression: json
}
},
"new_storage_per_byte": 1,
"vm_initialization": 2000
"vm_initialization": {
"HeavyOperation": {
"base": 2000,
"gas_per_unit": 0
}
}
},
"base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,12 @@ expression: json
}
},
"new_storage_per_byte": 1,
"vm_initialization": 2000
"vm_initialization": {
"HeavyOperation": {
"base": 2000,
"gas_per_unit": 0
}
}
},
"base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,12 @@ expression: json
}
},
"new_storage_per_byte": 1,
"vm_initialization": 2000
"vm_initialization": {
"HeavyOperation": {
"base": 2000,
"gas_per_unit": 0
}
}
},
"base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000"
},
Expand Down
2 changes: 1 addition & 1 deletion crates/client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ type GasCosts {
swwq: DependentCost!
contractRoot: DependentCost!
stateRoot: DependentCost!
vmInitialization: U64!
vmInitialization: DependentCost!
newStoragePerByte: U64!
}

Expand Down
2 changes: 1 addition & 1 deletion crates/client/src/client/schema/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ include_from_impls_and_cynic! {
// Non-opcodes prices
pub contract_root: DependentCost,
pub state_root: DependentCost,
pub vm_initialization: U64,
pub vm_initialization: DependentCost,
pub new_storage_per_byte: U64,
}
}
Expand Down
Loading
Loading