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

Added price benchmark for vm_initialization #1502

Merged
merged 10 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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 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
110 changes: 110 additions & 0 deletions benches/benches/vm_initialization.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
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>,
) -> Checked<Script> {
let consensus_params = ConsensusParameters::default();
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");

// Generate N data points
const N: usize = 18;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this N come from?

Copy link
Collaborator Author

@xgreenx xgreenx Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is calculated based on the current script data size limit. I replaced it with the corresponding check instead 5de31e9

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
Loading