Skip to content

Commit 7b5cdcf

Browse files
committed
chore: Second pass on wasmtime config
1 parent 17072f1 commit 7b5cdcf

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

fvm/src/machine/engine.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ use anyhow::{anyhow, Context};
77
use cid::Cid;
88
use fvm_ipld_blockstore::Blockstore;
99
use fvm_wasm_instrument::gas_metering::GAS_COUNTER_NAME;
10-
use wasmtime::{Global, GlobalType, Linker, Memory, MemoryType, Module, Mutability, Val, ValType};
10+
use wasmtime::OptLevel::Speed;
11+
use wasmtime::{
12+
Global, GlobalType, InstanceAllocationStrategy, InstanceLimits, Linker, Memory, MemoryType,
13+
Module, Mutability, PoolingAllocationStrategy, Val, ValType,
14+
};
1115

1216
use crate::gas::WasmGasPrices;
1317
use crate::machine::NetworkConfig;
@@ -69,9 +73,12 @@ pub fn default_wasmtime_config() -> wasmtime::Config {
6973
let mut c = wasmtime::Config::default();
7074

7175
// wasmtime default: false
76+
// We don't want threads, there is no way to ensure determisism
7277
c.wasm_threads(false);
7378

7479
// wasmtime default: true
80+
// simd isn't supported in wasm-instrument, but if we add support there, we can probably enable this.
81+
// Note: stack limits may need adjusting after this is enabled
7582
c.wasm_simd(false);
7683

7784
// wasmtime default: false
@@ -81,18 +88,23 @@ pub fn default_wasmtime_config() -> wasmtime::Config {
8188
c.wasm_memory64(false);
8289

8390
// wasmtime default: true
91+
// Note: wasm-instrument only supports this at a basic level, for M2 we will
92+
// need to add more advanced support
8493
c.wasm_bulk_memory(true);
8594

8695
// wasmtime default: false
8796
c.wasm_module_linking(false);
8897

8998
// wasmtime default: true
90-
c.wasm_multi_value(false); // ??
99+
// we should be able to enable this for M2, just need to make sure that it's
100+
// handled correctly in wasm-instrument
101+
c.wasm_multi_value(false);
91102

92103
// wasmtime default: depends on the arch
93104
// > This is true by default on x86-64, and false by default on other architectures.
94105
//
95-
// Not supported in wasm-instrument/parity-wasm
106+
// Not supported in wasm-instrument/parity-wasm; adding support will be complicated.
107+
// Note: stack limits may need adjusting after this is enabled
96108
c.wasm_reference_types(false);
97109

98110
// wasmtime default: false
@@ -105,13 +117,29 @@ pub fn default_wasmtime_config() -> wasmtime::Config {
105117
// > not enabled by default.
106118
c.cranelift_nan_canonicalization(true);
107119

120+
// wasmtime default: 512KiB
108121
// Set to something much higher than the instrumented limiter.
109-
c.max_wasm_stack(64 << 20).unwrap();
122+
// Note: This is in bytes, while the instrumented limit is in stack elements
123+
c.max_wasm_stack(4 << 20).unwrap();
110124

111125
// Execution cost accouting is done through wasm instrumentation,
112126
c.consume_fuel(false);
113-
114-
// c.cranelift_opt_level(Speed); ?
127+
c.epoch_interruption(false);
128+
129+
// Disable debug-related things, wasm-instrument doesn't fix debug info
130+
// yet, so those aren't useful, just add overhead
131+
c.debug_info(false);
132+
c.generate_address_map(false);
133+
c.cranelift_debug_verifier(false);
134+
135+
// Reiterate some defaults
136+
c.guard_before_linear_memory(true);
137+
c.interruptable(false);
138+
c.parallel_compilation(true);
139+
140+
// Doesn't seem to have significant impact on the time it takes to load code
141+
// todo(M2): make sure this is guaranteed to run in linear time.
142+
c.cranelift_opt_level(Speed);
115143

116144
c
117145
}

0 commit comments

Comments
 (0)