Update Wasm benchmarks (#2957)

In https://github.com/paritytech/polkadot-sdk/pull/2941 we found out
that the new Wasmi (register) is very effective at optimizing away
certain benchmark bytecode constructs in a way that created an unfair
advantage over Wasmi (stack) which yielded our former benchmarks to be
ineffective at properly measuring the performance impact.

This PR adjusts both affected benchmarks to fix the stated problems.
Affected are
- `instr_i64const` -> `instr_i64add`: Renamed since it now measures the
performance impact of the Wasm `i64.add` instruction with locals as
inputs and outputs. This makes it impossible for Wasmi (register) to
aggressively optimize away the entire function body (as it previously
did) but still provides a way for Wasmi (register) to shine with its
register based execution model.
- `call_with_code_per_byte`: Now uses `local.get` instead of `i32.const`
for the `if` condition which prevents Wasmi (register) to aggressively
optimizing away whole parts of the `if` creating an unfair advantage.

cc @athei

---------

Co-authored-by: command-bot <>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Ignacio Palacios <ignacio.palacios.santos@gmail.com>
This commit is contained in:
Robin Freyler
2024-01-19 20:36:16 +01:00
committed by GitHub
parent 320b52892e
commit e02c5204b3
4 changed files with 697 additions and 657 deletions
+6 -16
View File
@@ -358,25 +358,12 @@ macro_rules! cost_args {
}
}
macro_rules! cost_instr_no_params {
($name:ident) => {
cost_args!($name, 1).ref_time() as u32
};
}
macro_rules! cost {
($name:ident) => {
cost_args!($name, 1)
};
}
macro_rules! cost_instr {
($name:ident, $num_params:expr) => {
cost_instr_no_params!($name)
.saturating_sub((cost_instr_no_params!(instr_i64const) / 2).saturating_mul($num_params))
};
}
impl Default for Limits {
fn default() -> Self {
Self {
@@ -396,10 +383,13 @@ impl Default for Limits {
}
impl<T: Config> Default for InstructionWeights<T> {
/// We price both `i64.const` and `drop` as `instr_i64const / 2`. The reason
/// for that is that we cannot benchmark either of them on its own.
/// We execute 6 different instructions therefore we have to divide the actual
/// computed gas costs by 6 to have a rough estimate as to how expensive each
/// single executed instruction is going to be.
fn default() -> Self {
Self { base: cost_instr!(instr_i64const, 1), _phantom: PhantomData }
let instr_cost = cost!(instr_i64_load_store).ref_time() as u32;
let base = instr_cost / 6;
Self { base, _phantom: PhantomData }
}
}