Skip to content

Commit

Permalink
fix per_byte benches
Browse files Browse the repository at this point in the history
  • Loading branch information
ukint-vs committed Nov 21, 2023
1 parent 5966de1 commit d03eb7b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
20 changes: 10 additions & 10 deletions pallets/gear/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,10 @@ benchmarks! {
// the most of the gear storages represented with this type.
db_write_per_byte {
// Code is the biggest data could be written into storage in gear runtime.
let c in 0 .. T::Schedule::get().limits.code_len / 1024;
let c in 0 .. T::Schedule::get().limits.code_len;

// Data to be written.
let data = vec![c as u8; 1024 * c as usize];
let data = vec![c as u8; c as usize];
}: {
// Inserting data into the storage.
BenchmarkStorage::<T>::insert(c, data);
Expand All @@ -445,10 +445,10 @@ benchmarks! {
// the most of the gear storages represented with this type.
db_read_per_byte {
// Code is the biggest data could be written into storage in gear runtime.
let c in 0 .. T::Schedule::get().limits.code_len / 1024;
let c in 0 .. T::Schedule::get().limits.code_len;

// Data to be queried further.
let data = vec![c as u8; 1024 * c as usize];
let data = vec![c as u8; c as usize];

// Placing data in storage to be able to query it.
BenchmarkStorage::<T>::insert(c, data);
Expand All @@ -459,9 +459,9 @@ benchmarks! {

// `c`: Size of the code in bytes.
instantiate_module_per_byte {
let c in 0 .. T::Schedule::get().limits.code_len / 1024;
let c in 0 .. T::Schedule::get().limits.code_len;

let WasmModule { code, .. } = WasmModule::<T>::sized(c * 1024, Location::Init);
let WasmModule { code, .. } = WasmModule::<T>::sized(c, Location::Init);
}: {
let ext = Externalities::new(default_processor_context::<T>());
Environment::new(ext, &code, DispatchKind::Init, Default::default(), max_pages::<T>().into()).unwrap();
Expand Down Expand Up @@ -646,7 +646,7 @@ benchmarks! {
//
// `s`: Size of the salt in bytes.
create_program {
let s in 0 .. code::max_pages::<T>() as u32 * 64 * 128;
let s in 0 .. MAX_PAYLOAD_LEN;

let caller = whitelisted_caller();
let origin = RawOrigin::Signed(caller);
Expand Down Expand Up @@ -680,7 +680,7 @@ benchmarks! {
// to be larger than the maximum size **after instrumentation**.
upload_program {
let c in 0 .. Perbill::from_percent(49).mul_ceil(T::Schedule::get().limits.code_len);
let s in 0 .. code::max_pages::<T>() as u32 * 64 * 128 * 1024;
let s in 0 .. MAX_PAYLOAD_LEN;
let salt = vec![42u8; s as usize];
let value = CurrencyOf::<T>::minimum_balance();
let caller = whitelisted_caller();
Expand Down Expand Up @@ -777,8 +777,8 @@ benchmarks! {
// first time after a new schedule was deployed: For every new schedule a program needs
// to re-run the instrumentation once.
reinstrument_per_byte {
let c in 0 .. T::Schedule::get().limits.code_len / 1_024;
let WasmModule { code, hash, .. } = WasmModule::<T>::sized(c * 1_024, Location::Handle);
let c in 0 .. T::Schedule::get().limits.code_len;
let WasmModule { code, hash, .. } = WasmModule::<T>::sized(c, Location::Handle);
let code = Code::try_new_mock_const_or_no_rules(code, false, Default::default()).unwrap();
let code_and_id = CodeAndId::new(code);
let code_id = code_and_id.code_id();
Expand Down
4 changes: 2 additions & 2 deletions pallets/gear/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ pub mod pallet {
/// - `SavedCode(H256)` - when the code is saved in storage.
#[pallet::call_index(0)]
#[pallet::weight(
<T as Config>::WeightInfo::upload_code(code.len() as u32 / 1024)
<T as Config>::WeightInfo::upload_code(code.len() as u32)
)]
pub fn upload_code(origin: OriginFor<T>, code: Vec<u8>) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
Expand Down Expand Up @@ -1357,7 +1357,7 @@ pub mod pallet {
/// has been removed.
#[pallet::call_index(1)]
#[pallet::weight(
<T as Config>::WeightInfo::upload_program(code.len() as u32 / 1024, salt.len() as u32)
<T as Config>::WeightInfo::upload_program(code.len() as u32, salt.len() as u32)
)]
pub fn upload_program(
origin: OriginFor<T>,
Expand Down
2 changes: 1 addition & 1 deletion pallets/gear/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ impl<T: Config> Default for MemoryWeights<T> {
load_page_data: to_weight!(to_cost_per_gear_page!(lazy_pages_load_page_storage_data)
.saturating_sub(to_cost_per_gear_page!(lazy_pages_signal_read))),
upload_page_data: to_weight!(cost!(db_write_per_byte)
.saturating_mul(KB_AMOUNT_IN_ONE_GEAR_PAGE)
.saturating_mul(GEAR_PAGE_SIZE)
.saturating_add(T::DbWeight::get().writes(1).ref_time())),
// TODO: make benches to calculate static page cost and mem grow cost (issue #2226)
static_page: Weight::from_parts(100, 0),
Expand Down

0 comments on commit d03eb7b

Please sign in to comment.