mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 19:21:13 +00:00
[contracts] Add per local weight for function call (#12806)
* Add per local weight for function call * ".git/.scripts/bench-bot.sh" pallet dev pallet_contracts * Update frame/contracts/src/benchmarking/mod.rs Co-authored-by: Alexander Theißen <alex.theissen@me.com> * apply suggestions from code review * ".git/.scripts/bench-bot.sh" pallet dev pallet_contracts * Update frame/contracts/src/benchmarking/mod.rs Co-authored-by: Alexander Theißen <alex.theissen@me.com> * tune the benchmark * ".git/.scripts/bench-bot.sh" pallet dev pallet_contracts * fix benches * ".git/.scripts/bench-bot.sh" pallet dev pallet_contracts Co-authored-by: command-bot <> Co-authored-by: Alexander Theißen <alex.theissen@me.com>
This commit is contained in:
@@ -29,11 +29,14 @@ use frame_support::traits::Get;
|
||||
use sp_core::crypto::UncheckedFrom;
|
||||
use sp_runtime::traits::Hash;
|
||||
use sp_std::{borrow::ToOwned, prelude::*};
|
||||
use wasm_instrument::parity_wasm::{
|
||||
builder,
|
||||
elements::{
|
||||
self, BlockType, CustomSection, External, FuncBody, Instruction, Instructions, Module,
|
||||
Section, ValueType,
|
||||
use wasm_instrument::{
|
||||
gas_metering,
|
||||
parity_wasm::{
|
||||
builder,
|
||||
elements::{
|
||||
self, BlockType, CustomSection, External, FuncBody, Instruction, Instructions, Module,
|
||||
Section, ValueType,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -541,7 +544,8 @@ where
|
||||
fn inject_gas_metering<T: Config>(module: Module) -> Module {
|
||||
let schedule = T::Schedule::get();
|
||||
let gas_rules = schedule.rules(&module, Determinism::Deterministic);
|
||||
wasm_instrument::gas_metering::inject(module, &gas_rules, "seal0").unwrap()
|
||||
let backend = gas_metering::host_function::Injector::new("seal0", "gas");
|
||||
gas_metering::inject(module, backend, &gas_rules).unwrap()
|
||||
}
|
||||
|
||||
fn inject_stack_metering<T: Config>(module: Module) -> Module {
|
||||
|
||||
@@ -2429,10 +2429,28 @@ benchmarks! {
|
||||
sbox.invoke();
|
||||
}
|
||||
|
||||
// w_per_local = w_bench
|
||||
instr_call_per_local {
|
||||
let l in 0 .. T::Schedule::get().limits.locals;
|
||||
let mut aux_body = body::plain(vec![
|
||||
Instruction::End,
|
||||
]);
|
||||
body::inject_locals(&mut aux_body, l);
|
||||
let mut sbox = Sandbox::from(&WasmModule::<T>::from(ModuleDefinition {
|
||||
aux_body: Some(aux_body),
|
||||
call_body: Some(body::repeated(INSTR_BENCHMARK_BATCH_SIZE, &[
|
||||
Instruction::Call(2), // call aux
|
||||
])),
|
||||
.. Default::default()
|
||||
}));
|
||||
}: {
|
||||
sbox.invoke();
|
||||
}
|
||||
|
||||
// w_local_get = w_bench - 1 * w_param
|
||||
instr_local_get {
|
||||
let r in 0 .. INSTR_BENCHMARK_BATCHES;
|
||||
let max_locals = T::Schedule::get().limits.stack_height.unwrap_or(512);
|
||||
let max_locals = T::Schedule::get().limits.locals;
|
||||
let mut call_body = body::repeated_dyn(r * INSTR_BENCHMARK_BATCH_SIZE, vec![
|
||||
RandomGetLocal(0, max_locals),
|
||||
Regular(Instruction::Drop),
|
||||
@@ -2449,7 +2467,7 @@ benchmarks! {
|
||||
// w_local_set = w_bench - 1 * w_param
|
||||
instr_local_set {
|
||||
let r in 0 .. INSTR_BENCHMARK_BATCHES;
|
||||
let max_locals = T::Schedule::get().limits.stack_height.unwrap_or(512);
|
||||
let max_locals = T::Schedule::get().limits.locals;
|
||||
let mut call_body = body::repeated_dyn(r * INSTR_BENCHMARK_BATCH_SIZE, vec![
|
||||
RandomI64Repeated(1),
|
||||
RandomSetLocal(0, max_locals),
|
||||
@@ -2466,7 +2484,7 @@ benchmarks! {
|
||||
// w_local_tee = w_bench - 2 * w_param
|
||||
instr_local_tee {
|
||||
let r in 0 .. INSTR_BENCHMARK_BATCHES;
|
||||
let max_locals = T::Schedule::get().limits.stack_height.unwrap_or(512);
|
||||
let max_locals = T::Schedule::get().limits.locals;
|
||||
let mut call_body = body::repeated_dyn(r * INSTR_BENCHMARK_BATCH_SIZE, vec![
|
||||
RandomI64Repeated(1),
|
||||
RandomTeeLocal(0, max_locals),
|
||||
|
||||
Reference in New Issue
Block a user