Skip to content

Commit

Permalink
fix(weight-diff): add missing fields (#4134)
Browse files Browse the repository at this point in the history
  • Loading branch information
StackOverflowExcept1on authored Aug 9, 2024
1 parent 0f0d773 commit 0a1fde4
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 15 deletions.
65 changes: 51 additions & 14 deletions utils/wasm-instrument/src/gas_metering/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ pub struct Schedule {
pub instruction_weights: InstructionWeights,
pub syscall_weights: SyscallWeights,
pub memory_weights: MemoryWeights,
pub module_instantiation_per_byte: Weight,
pub instantiation_weights: InstantiationWeights,
pub db_write_per_byte: Weight,
pub db_read_per_byte: Weight,
pub code_instrumentation_cost: Weight,
pub code_instrumentation_byte_cost: Weight,
pub load_allocations_weight: Weight,
}

impl Default for Schedule {
Expand All @@ -40,10 +41,7 @@ impl Default for Schedule {
instruction_weights: InstructionWeights::default(),
syscall_weights: SyscallWeights::default(),
memory_weights: MemoryWeights::default(),
module_instantiation_per_byte: Weight {
ref_time: 192,
proof_size: 0,
},
instantiation_weights: InstantiationWeights::default(),
db_write_per_byte: Weight {
ref_time: 237,
proof_size: 0,
Expand All @@ -53,11 +51,15 @@ impl Default for Schedule {
proof_size: 0,
},
code_instrumentation_cost: Weight {
ref_time: 230751537,
proof_size: 3682,
ref_time: 285084454,
proof_size: 3791,
},
code_instrumentation_byte_cost: Weight {
ref_time: 59895,
ref_time: 623806,
proof_size: 0,
},
load_allocations_weight: Weight {
ref_time: 19776,
proof_size: 0,
},
}
Expand Down Expand Up @@ -87,7 +89,7 @@ impl Default for Limits {
globals: 256,
locals: 1024,
parameters: 128,
memory_pages: 512,
memory_pages: 32768,
table_size: 4096,
table_number: 100,
br_table_size: 256,
Expand Down Expand Up @@ -655,7 +657,6 @@ pub struct MemoryWeights {
pub lazy_pages_host_func_write_after_read: Weight,
pub load_page_data: Weight,
pub upload_page_data: Weight,
pub static_page: Weight,
pub mem_grow: Weight,
pub mem_grow_per_page: Weight,
pub parachain_read_heuristic: Weight,
Expand Down Expand Up @@ -696,10 +697,6 @@ impl Default for MemoryWeights {
ref_time: 103888768,
proof_size: 0,
},
static_page: Weight {
ref_time: 100,
proof_size: 0,
},
mem_grow: Weight {
ref_time: 810343,
proof_size: 0,
Expand All @@ -716,6 +713,46 @@ impl Default for MemoryWeights {
}
}

pub struct InstantiationWeights {
pub code_section_per_byte: Weight,
pub data_section_per_byte: Weight,
pub global_section_per_byte: Weight,
pub table_section_per_byte: Weight,
pub element_section_per_byte: Weight,
pub type_section_per_byte: Weight,
}

impl Default for InstantiationWeights {
fn default() -> Self {
Self {
code_section_per_byte: Weight {
ref_time: 192,
proof_size: 0,
},
data_section_per_byte: Weight {
ref_time: 452,
proof_size: 0,
},
global_section_per_byte: Weight {
ref_time: 2359,
proof_size: 0,
},
table_section_per_byte: Weight {
ref_time: 350,
proof_size: 0,
},
element_section_per_byte: Weight {
ref_time: 18492,
proof_size: 0,
},
type_section_per_byte: Weight {
ref_time: 254,
proof_size: 0,
},
}
}
}

pub struct Weight {
pub ref_time: u64,
pub proof_size: u64,
Expand Down
11 changes: 10 additions & 1 deletion utils/weight-diff/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ struct DeserializableSchedule {
instruction_weights: IndexMap<String, Value>,
syscall_weights: IndexMap<String, Weight>,
memory_weights: IndexMap<String, Weight>,
instantiation_weights: IndexMap<String, Weight>,
#[serde(flatten)]
other_fields: IndexMap<String, Weight>,
}
Expand Down Expand Up @@ -212,7 +213,12 @@ impl<'ast> Visit<'ast> for StructuresVisitor {
let structure_name = node.ident.to_string();
if !matches!(
structure_name.as_str(),
"Schedule" | "Limits" | "InstructionWeights" | "SyscallWeights" | "MemoryWeights"
"Schedule"
| "Limits"
| "InstructionWeights"
| "SyscallWeights"
| "MemoryWeights"
| "InstantiationWeights"
) {
return;
}
Expand Down Expand Up @@ -377,6 +383,9 @@ fn main() {
"InstructionWeights" => &raw_schedule["instruction_weights"][field_name],
"SyscallWeights" => &raw_schedule["syscall_weights"][field_name],
"MemoryWeights" => &raw_schedule["memory_weights"][field_name],
"InstantiationWeights" => {
&raw_schedule["instantiation_weights"][field_name]
}
_ => &raw_schedule,
};

Expand Down

0 comments on commit 0a1fde4

Please sign in to comment.