AOT supported
Closed this issue · 3 comments
jiaohu commented
Is there any way to use aot mode ?
alexcrichton commented
You can use Serialize
to get a compiled module's artifact and NewModuleDeserialize
to reuse that, so yes.
jiaohu commented
@alexcrichton so, aot mode is as below ?
func Benchmark1(b *testing.B) {
eg := wasmtime.NewEngine()
wasm, err := wasmtime.Wat2Wasm(`
(module
;; Define the optional module name. '$' prefixing is a part of the text format.
$wasm/math
;; add returns $x+$y.
;;
;; Notes:
;; * The stack begins empty and anything left must match the result type.
;; * export allows api.Module to return this via ExportedFunction("add")
(func (export "add") (param $x i32) (param $y i32) (result i32)
local.get $x ;; stack: [$x]
local.get $y ;; stack: [$x, $y]
i32.add ;; stack: [$x+$y]
)
)
`)
assert.Nil(b, err)
module, err := wasmtime.NewModule(eg, wasm)
assert.Nil(b, err)
s, err := module.Serialize()
assert.Nil(b, err)
m, err := wasmtime.NewModuleDeserialize(eg, s)
assert.Nil(b, err)
store := wasmtime.NewStore(eg)
instance, err := wasmtime.NewInstance(store, m, []wasmtime.AsExtern{})
assert.Nil(b, err)
run := instance.GetFunc(store, "add")
if run == nil {
panic("not a function")
}
for i := 0; i < b.N; i++ {
x, y := uint64(1), uint64(2)
_, err = run.Call(store, x, y)
}
}
alexcrichton commented
Yes, the latter half of that can be split to a separate new process if you'd like.