Skip to content

Commit

Permalink
improve wasmtime setup
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Jun 26, 2024
1 parent 6b6c8fb commit e55b81e
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions runtime/webassembly.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,37 @@ type WasmtimeWebAssemblyModule struct {
func NewWasmtimeWebAssemblyModule(bytes []byte) (stdlib.WebAssemblyModule, error) {
config := wasmtime.NewConfig()

Check failure on line 39 in runtime/webassembly.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: wasmtime (typecheck)

// Deterministic configuration inspired by
// https://github.com/dfinity/ic/blob/a0ab22537bdf65bd1f473654d49283e4f95f5a61/rs/embedders/README.adoc#nondeterminism

config.SetConsumeFuel(true)
config.SetMaxWasmStack(512 * 1024)

// TODO: define max stack size
const todoMaxStackSize = 512 * 1024
config.SetMaxWasmStack(todoMaxStackSize)

// Enable bulk memory operations,
// programs can use them to operate on memory more efficiently.
config.SetWasmBulkMemory(true)

// Deterministic configuration inspired by
// https://github.com/dfinity/ic/blob/a0ab22537bdf65bd1f473654d49283e4f95f5a61/rs/embedders/README.adoc#nondeterminism

config.SetWasmThreads(false)
config.SetWasmReferenceTypes(false)
// TODO: disable all SIMD related functionality.
// Depends on https://github.com/bytecodealliance/wasmtime-go/pull/224
// config.SetWasmSIMD(false)
config.SetWasmMemory64(false)
config.SetWasmMultiMemory(false)
config.SetWasmMultiValue(false)
config.SetWasmSIMD(false)
config.SetWasmRelaxedSIMD(false)
config.SetWasmRelaxedSIMDDeterministic(false)

// NaN canonicalization is needed for determinism.
config.SetStrategy(wasmtime.StrategyCranelift)
config.SetCraneliftFlag("enable_nan_canonicalization", "true")

// Disable optimizations to keep compilation simple and fast.
config.SetCraneliftOptLevel(wasmtime.OptLevelNone)

// Disable other features for now,
// maybe consider enabling them later.
config.SetWasmReferenceTypes(false)
config.SetWasmMemory64(false)
config.SetWasmMultiMemory(false)
config.SetWasmMultiValue(false)

engine := wasmtime.NewEngineWithConfig(config)

store := wasmtime.NewStore(engine)
Expand Down

0 comments on commit e55b81e

Please sign in to comment.