@@ -17,6 +17,8 @@ use super::limiting_tunables::LimitingTunables;
17
17
/// https://github.com/WebAssembly/memory64/blob/master/proposals/memory64/Overview.md
18
18
const MAX_WASM_PAGES : u32 = 65536 ;
19
19
20
+ // This function is hashed and put into the `module_version_discriminator` because it is used as
21
+ // part of the compilation process. If it changes, modules need to be recompiled.
20
22
#[ hash_function( const_name = "COST_FUNCTION_HASH" ) ]
21
23
fn cost ( operator : & Operator ) -> u64 {
22
24
// A flat fee for each operation
@@ -25,13 +27,18 @@ fn cost(operator: &Operator) -> u64 {
25
27
// In https://github.com/CosmWasm/cosmwasm/pull/1042 a profiler is developed to
26
28
// identify runtime differences between different Wasm operation, but this is not yet
27
29
// precise enough to derive insights from it.
28
- //
29
- // Please note that any changes to this function need to be accompanied by a bump of
30
- // `MODULE_SERIALIZATION_VERSION` to avoid cached modules from using different amounts of gas
31
- // compared to newly compiled ones.
32
30
const GAS_PER_OPERATION : u64 = 115 ;
33
31
34
32
if is_accounting ( operator) {
33
+ // Accounting operators are operators where the `Metering` middleware injects instructions
34
+ // to count the gas usage and check for gas exhaustion. Therefore they are more expensive.
35
+ //
36
+ // Benchmarks show that the overhead is about 14 times the cost of a normal operation.
37
+ // To benchmark this, set `GAS_PER_OPERATION = 100` and run the "infinite loop" and
38
+ // "argon2" benchmarks. From the "Gas used" output, you can calculate the number of
39
+ // operations and from that together with the run time the expected gas value per operation:
40
+ // GAS_PER_OP = GAS_TARGET_PER_SEC / (NUM_OPS / RUNTIME_IN_SECS)
41
+ // This is repeated with different multipliers to bring the two benchmarks closer together.
35
42
GAS_PER_OPERATION * 14
36
43
} else {
37
44
GAS_PER_OPERATION
0 commit comments