@@ -320,6 +320,25 @@ benchmarks! {
320
320
Contracts :: <T >:: reinstrument_module( & mut module, & schedule) ?;
321
321
}
322
322
323
+ // The weight of loading and decoding of a contract's code per kilobyte.
324
+ code_load {
325
+ let c in 0 .. T :: Schedule :: get( ) . limits. code_len / 1024 ;
326
+ let WasmModule { code, hash, .. } = WasmModule :: <T >:: dummy_with_bytes( c * 1024 ) ;
327
+ Contracts :: <T >:: store_code_raw( code) ?;
328
+ } : {
329
+ <PrefabWasmModule <T >>:: from_storage_noinstr( hash) ?;
330
+ }
331
+
332
+ // The weight of changing the refcount of a contract's code per kilobyte.
333
+ code_refcount {
334
+ let c in 0 .. T :: Schedule :: get( ) . limits. code_len / 1024 ;
335
+ let WasmModule { code, hash, .. } = WasmModule :: <T >:: dummy_with_bytes( c * 1024 ) ;
336
+ Contracts :: <T >:: store_code_raw( code) ?;
337
+ let mut gas_meter = GasMeter :: new( Weight :: max_value( ) ) ;
338
+ } : {
339
+ <PrefabWasmModule <T >>:: add_user( hash, & mut gas_meter) ?;
340
+ }
341
+
323
342
// This constructs a contract that is maximal expensive to instrument.
324
343
// It creates a maximum number of metering blocks per byte.
325
344
// The size of the salt influences the runtime because is is hashed in order to
@@ -352,16 +371,14 @@ benchmarks! {
352
371
}
353
372
354
373
// Instantiate uses a dummy contract constructor to measure the overhead of the instantiate.
355
- // `c`: Size of the code in kilobytes.
356
374
// `s`: Size of the salt in kilobytes.
357
375
instantiate {
358
- let c in 0 .. T :: Schedule :: get( ) . limits. code_len / 1024 ;
359
376
let s in 0 .. code:: max_pages:: <T >( ) * 64 ;
360
377
let salt = vec![ 42u8 ; ( s * 1024 ) as usize ] ;
361
378
let endowment = caller_funding:: <T >( ) / 3u32 . into( ) ;
362
379
let caller = whitelisted_caller( ) ;
363
380
T :: Currency :: make_free_balance_be( & caller, caller_funding:: <T >( ) ) ;
364
- let WasmModule { code, hash, .. } = WasmModule :: <T >:: dummy_with_bytes ( c * 1024 ) ;
381
+ let WasmModule { code, hash, .. } = WasmModule :: <T >:: dummy ( ) ;
365
382
let origin = RawOrigin :: Signed ( caller. clone( ) ) ;
366
383
let addr = Contracts :: <T >:: contract_address( & caller, & hash, & salt) ;
367
384
Contracts :: <T >:: store_code_raw( code) ?;
@@ -380,12 +397,10 @@ benchmarks! {
380
397
// won't call `seal_input` in its constructor to copy the data to contract memory.
381
398
// The dummy contract used here does not do this. The costs for the data copy is billed as
382
399
// part of `seal_input`.
383
- // `c`: Size of the code in kilobytes.
384
400
call {
385
- let c in 0 .. T :: Schedule :: get( ) . limits. code_len / 1024 ;
386
401
let data = vec![ 42u8 ; 1024 ] ;
387
402
let instance = Contract :: <T >:: with_caller(
388
- whitelisted_caller( ) , WasmModule :: dummy_with_bytes ( c * 1024 ) , vec![ ] , Endow :: CollectRent
403
+ whitelisted_caller( ) , WasmModule :: dummy ( ) , vec![ ] , Endow :: CollectRent
389
404
) ?;
390
405
let value = T :: Currency :: minimum_balance( ) * 100u32 . into( ) ;
391
406
let origin = RawOrigin :: Signed ( instance. caller. clone( ) ) ;
@@ -720,43 +735,6 @@ benchmarks! {
720
735
}
721
736
}
722
737
723
- seal_terminate_per_code_kb {
724
- let c in 0 .. T :: Schedule :: get( ) . limits. code_len / 1024 ;
725
- let beneficiary = account:: <T :: AccountId >( "beneficiary" , 0 , 0 ) ;
726
- let beneficiary_bytes = beneficiary. encode( ) ;
727
- let beneficiary_len = beneficiary_bytes. len( ) ;
728
- let code = WasmModule :: <T >:: from( ModuleDefinition {
729
- memory: Some ( ImportedMemory :: max:: <T >( ) ) ,
730
- imported_functions: vec![ ImportedFunction {
731
- module: "seal0" ,
732
- name: "seal_terminate" ,
733
- params: vec![ ValueType :: I32 , ValueType :: I32 ] ,
734
- return_type: None ,
735
- } ] ,
736
- data_segments: vec![
737
- DataSegment {
738
- offset: 0 ,
739
- value: beneficiary_bytes,
740
- } ,
741
- ] ,
742
- call_body: Some ( body:: repeated( 1 , & [
743
- Instruction :: I32Const ( 0 ) , // beneficiary_ptr
744
- Instruction :: I32Const ( beneficiary_len as i32 ) , // beneficiary_len
745
- Instruction :: Call ( 0 ) ,
746
- ] ) ) ,
747
- dummy_section: c * 1024 ,
748
- .. Default :: default ( )
749
- } ) ;
750
- let instance = Contract :: <T >:: new( code, vec![ ] , Endow :: Max ) ?;
751
- let origin = RawOrigin :: Signed ( instance. caller. clone( ) ) ;
752
- assert_eq!( T :: Currency :: total_balance( & beneficiary) , 0u32 . into( ) ) ;
753
- assert_eq!( T :: Currency :: total_balance( & instance. account_id) , Endow :: max:: <T >( ) ) ;
754
- } : call( origin, instance. addr, 0u32 . into( ) , Weight :: max_value( ) , vec![ ] )
755
- verify {
756
- assert_eq!( T :: Currency :: total_balance( & instance. account_id) , 0u32 . into( ) ) ;
757
- assert_eq!( T :: Currency :: total_balance( & beneficiary) , Endow :: max:: <T >( ) ) ;
758
- }
759
-
760
738
seal_restore_to {
761
739
let r in 0 .. 1 ;
762
740
@@ -836,18 +814,15 @@ benchmarks! {
836
814
}
837
815
}
838
816
839
- // `c`: Code size of caller contract
840
- // `t`: Code size of tombstone contract
841
817
// `d`: Number of supplied delta keys
842
- seal_restore_to_per_code_kb_delta {
843
- let c in 0 .. T :: Schedule :: get( ) . limits. code_len / 1024 ;
844
- let t in 0 .. T :: Schedule :: get( ) . limits. code_len / 1024 ;
818
+ seal_restore_to_per_delta {
845
819
let d in 0 .. API_BENCHMARK_BATCHES ;
846
- let mut tombstone = ContractWithStorage :: <T >:: with_code(
847
- WasmModule :: <T >:: dummy_with_bytes( t * 1024 ) , 0 , 0
848
- ) ?;
820
+ let mut tombstone = ContractWithStorage :: <T >:: new( 0 , 0 ) ?;
849
821
tombstone. evict( ) ?;
850
- let delta = create_storage:: <T >( d * API_BENCHMARK_BATCH_SIZE , T :: Schedule :: get( ) . limits. payload_len) ?;
822
+ let delta = create_storage:: <T >(
823
+ d * API_BENCHMARK_BATCH_SIZE ,
824
+ T :: Schedule :: get( ) . limits. payload_len,
825
+ ) ?;
851
826
852
827
let dest = tombstone. contract. account_id. encode( ) ;
853
828
let dest_len = dest. len( ) ;
@@ -909,7 +884,6 @@ benchmarks! {
909
884
Instruction :: Call ( 0 ) ,
910
885
Instruction :: End ,
911
886
] ) ) ,
912
- dummy_section: c * 1024 ,
913
887
.. Default :: default ( )
914
888
} ) ;
915
889
@@ -1393,8 +1367,7 @@ benchmarks! {
1393
1367
let origin = RawOrigin :: Signed ( instance. caller. clone( ) ) ;
1394
1368
} : call( origin, instance. addr, 0u32 . into( ) , Weight :: max_value( ) , vec![ ] )
1395
1369
1396
- seal_call_per_code_transfer_input_output_kb {
1397
- let c in 0 .. T :: Schedule :: get( ) . limits. code_len / 1024 ;
1370
+ seal_call_per_transfer_input_output_kb {
1398
1371
let t in 0 .. 1 ;
1399
1372
let i in 0 .. code:: max_pages:: <T >( ) * 64 ;
1400
1373
let o in 0 .. ( code:: max_pages:: <T >( ) - 1 ) * 64 ;
@@ -1417,7 +1390,6 @@ benchmarks! {
1417
1390
Instruction :: Call ( 0 ) ,
1418
1391
Instruction :: End ,
1419
1392
] ) ) ,
1420
- dummy_section: c * 1024 ,
1421
1393
.. Default :: default ( )
1422
1394
} ) ;
1423
1395
let callees = ( 0 ..API_BENCHMARK_BATCH_SIZE )
@@ -1593,8 +1565,7 @@ benchmarks! {
1593
1565
}
1594
1566
}
1595
1567
1596
- seal_instantiate_per_code_input_output_salt_kb {
1597
- let c in 0 .. T :: Schedule :: get( ) . limits. code_len / 1024 ;
1568
+ seal_instantiate_per_input_output_salt_kb {
1598
1569
let i in 0 .. ( code:: max_pages:: <T >( ) - 1 ) * 64 ;
1599
1570
let o in 0 .. ( code:: max_pages:: <T >( ) - 1 ) * 64 ;
1600
1571
let s in 0 .. ( code:: max_pages:: <T >( ) - 1 ) * 64 ;
@@ -1617,7 +1588,6 @@ benchmarks! {
1617
1588
Instruction :: Call ( 0 ) ,
1618
1589
Instruction :: End ,
1619
1590
] ) ) ,
1620
- dummy_section: c * 1024 ,
1621
1591
.. Default :: default ( )
1622
1592
} ) ;
1623
1593
let hash = callee_code. hash. clone( ) ;
0 commit comments