From dbaad0c0f88b58dd5ed03d22b7c1cd75585a44fb Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Tue, 26 Nov 2024 15:26:08 +0100 Subject: [PATCH 1/5] Update bhsh bench --- benches/benches/vm_set/blockchain.rs | 35 +++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/benches/benches/vm_set/blockchain.rs b/benches/benches/vm_set/blockchain.rs index cd51bf6dbc9..a18773bc998 100644 --- a/benches/benches/vm_set/blockchain.rs +++ b/benches/benches/vm_set/blockchain.rs @@ -65,6 +65,7 @@ pub struct BenchDb { db: GenesisDatabase, /// Used for RAII cleanup. Contents of this directory are deleted on drop. _tmp_dir: utils::ShallowTempDir, + latest_block: u32, } impl BenchDb { @@ -122,18 +123,31 @@ impl BenchDb { &block.compress(&chain_config.consensus_parameters.chain_id()), ) .unwrap(); - Ok(Self { _tmp_dir: tmp_dir, db: database, + latest_block: 0, }) } + fn add_blocks(&mut self, nb_blocks: u32) { + for i in 1..=nb_blocks { + let block = fuel_core::service::genesis::create_genesis_block(&Config::local_node()); + let config = Config::local_node(); + let chain_config = config.snapshot_reader.chain_config(); + self.db + .storage::() + .insert(&i.into(), &block.compress(&chain_config.consensus_parameters.chain_id())) + .unwrap(); + } + self.latest_block = nb_blocks; + } + /// Creates a `VmDatabase` instance. fn to_vm_database(&self) -> VmStorage> { let consensus = ConsensusHeader { prev_root: Default::default(), - height: 1.into(), + height: self.latest_block.into(), time: Tai64::UNIX_EPOCH, generated: (), }; @@ -517,14 +531,23 @@ pub fn run(c: &mut Criterion) { VmBench::new(op::bhei(0x10)), ); + let mut db = BenchDb::new(&VmBench::CONTRACT).expect("Unable to fill contract storage"); + db.add_blocks(10000); + run_group_ref( &mut c.benchmark_group("bhsh"), "bhsh", - VmBench::new(op::bhsh(0x10, RegId::ZERO)).with_prepare_script(vec![ - op::movi(0x10, Bytes32::LEN.try_into().unwrap()), + VmBench::new(op::bhsh(RegId::HP, 0x11)) + .prepend_prepare_script(vec![ + // Store number of bytes we want to alloc for the future result + op::movi(0x10, 0x20), + // Allocate space for the future result op::aloc(0x10), - op::move_(0x10, RegId::HP), - ]), + // Add block height to 0x11 + op::movi(0x11, 0xc9) + ]) + .with_height(0xca.into()) + .with_db(db.to_vm_database()) ); run_group_ref( From 91e28c01a54f6c9a19a4ae39a6aa0e16e0996709 Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Tue, 26 Nov 2024 15:40:48 +0100 Subject: [PATCH 2/5] Format and new gas --- benches/benches/vm_set/blockchain.rs | 31 ++++++++++++++++------------ benches/src/default_gas_costs.rs | 2 +- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/benches/benches/vm_set/blockchain.rs b/benches/benches/vm_set/blockchain.rs index a18773bc998..7ae4dd86221 100644 --- a/benches/benches/vm_set/blockchain.rs +++ b/benches/benches/vm_set/blockchain.rs @@ -132,12 +132,16 @@ impl BenchDb { fn add_blocks(&mut self, nb_blocks: u32) { for i in 1..=nb_blocks { - let block = fuel_core::service::genesis::create_genesis_block(&Config::local_node()); + let block = + fuel_core::service::genesis::create_genesis_block(&Config::local_node()); let config = Config::local_node(); let chain_config = config.snapshot_reader.chain_config(); self.db .storage::() - .insert(&i.into(), &block.compress(&chain_config.consensus_parameters.chain_id())) + .insert( + &i.into(), + &block.compress(&chain_config.consensus_parameters.chain_id()), + ) .unwrap(); } self.latest_block = nb_blocks; @@ -531,23 +535,24 @@ pub fn run(c: &mut Criterion) { VmBench::new(op::bhei(0x10)), ); - let mut db = BenchDb::new(&VmBench::CONTRACT).expect("Unable to fill contract storage"); + let mut db = + BenchDb::new(&VmBench::CONTRACT).expect("Unable to fill contract storage"); db.add_blocks(10000); run_group_ref( &mut c.benchmark_group("bhsh"), "bhsh", VmBench::new(op::bhsh(RegId::HP, 0x11)) - .prepend_prepare_script(vec![ - // Store number of bytes we want to alloc for the future result - op::movi(0x10, 0x20), - // Allocate space for the future result - op::aloc(0x10), - // Add block height to 0x11 - op::movi(0x11, 0xc9) - ]) - .with_height(0xca.into()) - .with_db(db.to_vm_database()) + .prepend_prepare_script(vec![ + // Store number of bytes we want to alloc for the future result + op::movi(0x10, 0x20), + // Allocate space for the future result + op::aloc(0x10), + // Add block height to 0x11 + op::movi(0x11, 0xc9), + ]) + .with_height(0xca.into()) + .with_db(db.to_vm_database()), ); run_group_ref( diff --git a/benches/src/default_gas_costs.rs b/benches/src/default_gas_costs.rs index 4af5ab16a66..f770326ee47 100644 --- a/benches/src/default_gas_costs.rs +++ b/benches/src/default_gas_costs.rs @@ -8,7 +8,7 @@ pub fn default_gas_costs() -> GasCostsValues { andi: 2, bal: 274, bhei: 2, - bhsh: 2, + bhsh: 32, burn: 7566, cb: 2, cfsi: 2, From 1f0d73af47e0ad0770c1fb5a69f740923c9f809c Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Mon, 16 Dec 2024 13:47:08 +0100 Subject: [PATCH 3/5] Update more chain config value --- .../src/tests/test_data/large_state/chain_config.json | 2 +- bin/fuel-core/chainspec/local-testnet/chain_config.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/e2e-test-client/src/tests/test_data/large_state/chain_config.json b/bin/e2e-test-client/src/tests/test_data/large_state/chain_config.json index d4ebcb607d5..23adc22f3fc 100644 --- a/bin/e2e-test-client/src/tests/test_data/large_state/chain_config.json +++ b/bin/e2e-test-client/src/tests/test_data/large_state/chain_config.json @@ -48,7 +48,7 @@ "andi": 2, "bal": 366, "bhei": 2, - "bhsh": 2, + "bhsh": 32, "burn": 33949, "cb": 2, "cfei": 2, diff --git a/bin/fuel-core/chainspec/local-testnet/chain_config.json b/bin/fuel-core/chainspec/local-testnet/chain_config.json index 58df0f6bc3e..3c59ee5ffa3 100644 --- a/bin/fuel-core/chainspec/local-testnet/chain_config.json +++ b/bin/fuel-core/chainspec/local-testnet/chain_config.json @@ -47,7 +47,7 @@ "andi": 2, "bal": 274, "bhei": 2, - "bhsh": 2, + "bhsh": 32, "burn": 7566, "cb": 2, "cfsi": 2, From c94e661ff2d9c59d171cc11ecfb76455a7a9efbe Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Mon, 16 Dec 2024 16:12:24 +0100 Subject: [PATCH 4/5] Add some script data to make the block bigger --- benches/benches/vm_set/blockchain.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/benches/benches/vm_set/blockchain.rs b/benches/benches/vm_set/blockchain.rs index 7ae4dd86221..2ac3c17bd6c 100644 --- a/benches/benches/vm_set/blockchain.rs +++ b/benches/benches/vm_set/blockchain.rs @@ -47,8 +47,11 @@ use fuel_core_types::{ }, fuel_tx::{ ContractIdExt, + Finalizable, Input, Output, + Transaction, + TransactionBuilder, Word, }, fuel_types::*, @@ -132,8 +135,13 @@ impl BenchDb { fn add_blocks(&mut self, nb_blocks: u32) { for i in 1..=nb_blocks { - let block = + let mut block = fuel_core::service::genesis::create_genesis_block(&Config::local_node()); + let transactions = block.transactions_mut(); + // Add a dummy transaction to the block to make the block bigger. + transactions.push(Transaction::Script( + TransactionBuilder::script(vec![], vec![1; 200_000]).finalize(), + )); let config = Config::local_node(); let chain_config = config.snapshot_reader.chain_config(); self.db From 9d2b834d52aa1fbf0ce92e8bdf33a1757e792bab Mon Sep 17 00:00:00 2001 From: Green Baneling Date: Thu, 26 Dec 2024 14:07:52 -0500 Subject: [PATCH 5/5] Apply suggestions from code review --- benches/benches/vm_set/blockchain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benches/benches/vm_set/blockchain.rs b/benches/benches/vm_set/blockchain.rs index 2ac3c17bd6c..0ee0ecacff1 100644 --- a/benches/benches/vm_set/blockchain.rs +++ b/benches/benches/vm_set/blockchain.rs @@ -553,7 +553,7 @@ pub fn run(c: &mut Criterion) { VmBench::new(op::bhsh(RegId::HP, 0x11)) .prepend_prepare_script(vec![ // Store number of bytes we want to alloc for the future result - op::movi(0x10, 0x20), + op::movi(0x10, Bytes32::LEN.try_into().unwrap()), // Allocate space for the future result op::aloc(0x10), // Add block height to 0x11