Skip to content

Commit

Permalink
Added price benchmark for vm_initialization (#1502)
Browse files Browse the repository at this point in the history
Closes #1442

---------

Co-authored-by: Brandon Vrooman <[email protected]>
  • Loading branch information
xgreenx and Brandon Vrooman authored Nov 22, 2023
1 parent d7392e8 commit c33dda5
Show file tree
Hide file tree
Showing 23 changed files with 222 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Description of the upcoming release here.

### Added

- [#1502](https://github.com/FuelLabs/fuel-core/pull/1502): Added price benchmark for `vm_initialization`.
- [#1492](https://github.com/FuelLabs/fuel-core/pull/1492): Support backward iteration in the RocksDB. It allows backward queries that were not allowed before.
- [#1490](https://github.com/FuelLabs/fuel-core/pull/1490): Add push and pop benchmarks.
- [#1485](https://github.com/FuelLabs/fuel-core/pull/1485): Prepare rc release of fuel core v0.21
Expand Down
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.0", 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
2 changes: 1 addition & 1 deletion benches/benches/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn set_full_word(r: RegisterId, v: Word) -> Vec<Instruction> {
ops
}

const BENCH_RECEIPTS: usize = (u16::MAX - 1) as usize;
const BENCH_RECEIPTS: usize = (u16::MAX - 4) as usize;

/// Testing receipt context
#[allow(dead_code)] // Unsure why this is needed, as the code is used
Expand Down
5 changes: 4 additions & 1 deletion benches/benches/vm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod contract;
mod utils;
mod vm_initialization;
mod vm_set;

use criterion::{
Expand All @@ -11,6 +12,7 @@ use criterion::{
Criterion,
};

use crate::vm_initialization::vm_initialization;
use contract::*;
use fuel_core_benches::*;
use fuel_core_types::fuel_asm::Instruction;
Expand Down Expand Up @@ -71,9 +73,10 @@ fn vm(c: &mut Criterion) {
crypto::run(c);
flow::run(c);
mem::run(c);
blockchain::run(c);
contract_root(c);
state_root(c);
blockchain::run(c);
vm_initialization(c);
}

criterion_group!(benches, vm);
Expand Down
114 changes: 114 additions & 0 deletions benches/benches/vm_initialization.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
use criterion::{
black_box,
Criterion,
Throughput,
};
use fuel_core_types::{
fuel_asm::{
op,
Instruction,
},
fuel_tx::{
policies::Policies,
AssetId,
ConsensusParameters,
Input,
Output,
Script,
Transaction,
Word,
},
fuel_types::canonical::Serialize,
fuel_vm::{
checked_transaction::{
Checked,
IntoChecked,
},
interpreter::NotSupportedEcal,
Interpreter,
},
};
use rand::{
rngs::StdRng,
Rng,
SeedableRng,
};

fn transaction<R: Rng>(
rng: &mut R,
script: Vec<u8>,
script_data: Vec<u8>,
consensus_params: &ConsensusParameters,
) -> Checked<Script> {
let inputs = (0..1)
.map(|_| {
Input::coin_predicate(
rng.gen(),
rng.gen(),
rng.gen(),
AssetId::BASE,
rng.gen(),
rng.gen(),
0,
vec![255; 1],
vec![255; 1],
)
})
.collect();

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

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; 32].into(); 1],
)
.into_checked_basic(Default::default(), consensus_params)
.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");

let consensus_params = ConsensusParameters::default();
let mut i = 5usize;
loop {
let size = 8 * (1 << i);
if size as u64 > consensus_params.script_params.max_script_data_length {
break
}
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, &consensus_params);
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");
})
});
i += 1;
}

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
Loading

0 comments on commit c33dda5

Please sign in to comment.