Skip to content

Commit

Permalink
Updated VM initialization benchmark to include many inputs and outputs (
Browse files Browse the repository at this point in the history
#1973)

Covers new behavior from FuelLabs/fuel-vm#770

### Before requesting review
- [x] I have reviewed the code myself
  • Loading branch information
xgreenx committed Jun 15, 2024
1 parent b412162 commit 83b2b70
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed
- [#1973](https://github.com/FuelLabs/fuel-core/pull/1973): Updated VM initialization benchmark to include many inputs and outputs.

## [Version 0.29.0]

### Added
Expand Down
34 changes: 28 additions & 6 deletions benches/benches/vm_initialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use fuel_core_types::{
Output,
Script,
Transaction,
TxParameters,
},
fuel_types::canonical::Serialize,
fuel_vm::{
Expand All @@ -39,7 +40,7 @@ fn transaction<R: Rng>(
script_data: Vec<u8>,
consensus_params: &ConsensusParameters,
) -> Checked<Script> {
let inputs = (0..1)
let mut inputs = (0..1)
.map(|_| {
Input::coin_predicate(
rng.gen(),
Expand All @@ -52,13 +53,33 @@ fn transaction<R: Rng>(
vec![255; 1],
)
})
.collect();
.collect::<Vec<_>>();

let outputs = (0..1)
const CONTRACTS_NUMBER: u16 = 254;

for i in 0..CONTRACTS_NUMBER {
inputs.push(Input::contract(
rng.gen(),
rng.gen(),
rng.gen(),
rng.gen(),
[i as u8; 32].into(),
));
}

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

for i in 0..CONTRACTS_NUMBER {
outputs.push(Output::contract(
i + 1,
Default::default(),
Default::default(),
));
}

Transaction::script(
1_000_000,
Expand All @@ -75,12 +96,13 @@ fn transaction<R: Rng>(

pub fn vm_initialization(c: &mut Criterion) {
let mut rng = StdRng::seed_from_u64(8586);
let consensus_params = ConsensusParameters::default();
let mut consensus_params = ConsensusParameters::default();
consensus_params.set_tx_params(TxParameters::default().with_max_size(256 * 1024));
let mut group = c.benchmark_group("vm_initialization");

// Increase the size of the script to measure the performance of the VM initialization
// with a large script. THe largest allowed script is 64 KB = 8 * 2^13 bytes.
const TX_SIZE_POWER_OF_TWO: usize = 12;
const TX_SIZE_POWER_OF_TWO: usize = 13;

for i in 5..=TX_SIZE_POWER_OF_TWO {
let size = 8 * (1 << i);
Expand Down

0 comments on commit 83b2b70

Please sign in to comment.