Skip to content

Commit

Permalink
benchmark: updates wazero
Browse files Browse the repository at this point in the history
  • Loading branch information
inkeliz authored Jul 5, 2022
2 parents d0b2740 + cb294a8 commit 023ef9c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
4 changes: 2 additions & 2 deletions benchmark/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ require (
github.com/google/flatbuffers v2.0.6+incompatible
github.com/google/gofuzz v1.2.0
github.com/r3labs/diff/v3 v3.0.0
github.com/tetratelabs/wazero v0.0.0-20220523092326-5ed31d3c495d
github.com/tetratelabs/wazero v0.0.0-20220630052417-63f6b2231142
golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9
golang.org/x/text v0.3.7
karmem.org v0.0.0-20220511165140-adc37bce9562
karmem.org v1.0.0
)

require (
Expand Down
8 changes: 2 additions & 6 deletions benchmark/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tetratelabs/wazero v0.0.0-20220506015640-0561190cb9af h1:5XXl5YM+VZsvXLHauwqkuk9vtF0jUjsnCA5VIfcNXaA=
github.com/tetratelabs/wazero v0.0.0-20220506015640-0561190cb9af/go.mod h1:Y4X/zO4sC2dJjZG9GDYNRbJGogfqFYJY/BbyKlOxXGI=
github.com/tetratelabs/wazero v0.0.0-20220520075501-ec3ada35a059 h1:dW1TqjUsbagUMSaJEOBkPKmUeeLpBAP/PnwKAdV7qcM=
github.com/tetratelabs/wazero v0.0.0-20220520075501-ec3ada35a059/go.mod h1:Y4X/zO4sC2dJjZG9GDYNRbJGogfqFYJY/BbyKlOxXGI=
github.com/tetratelabs/wazero v0.0.0-20220523092326-5ed31d3c495d h1:OVaIrGwhWWvBsztdGYShF5XQUrf+n3d4rsEahI4NahI=
github.com/tetratelabs/wazero v0.0.0-20220523092326-5ed31d3c495d/go.mod h1:Y4X/zO4sC2dJjZG9GDYNRbJGogfqFYJY/BbyKlOxXGI=
github.com/tetratelabs/wazero v0.0.0-20220630052417-63f6b2231142 h1:ZnK50yYXmYRlAOpOzYw6Xu/QWU2kP8bDeVLQDzQtTas=
github.com/tetratelabs/wazero v0.0.0-20220630052417-63f6b2231142/go.mod h1:Y4X/zO4sC2dJjZG9GDYNRbJGogfqFYJY/BbyKlOxXGI=
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
24 changes: 10 additions & 14 deletions benchmark/main_wasi_wazero.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"fmt"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/wasi"
"github.com/tetratelabs/wazero/wasi_snapshot_preview1"
"golang.org/x/text/encoding/unicode"
"os"
"path/filepath"
Expand All @@ -21,8 +21,9 @@ func initWasm(b interface {
}, fn ...string) Wasm {
w := &WasmWazero{}
var err error
runtime := wazero.NewRuntimeWithConfig(wazero.NewRuntimeConfigCompiler().WithWasmCore2())
w.modules[0], err = wasi.InstantiateSnapshotPreview1(context.Background(), runtime)
w.runtime = wazero.NewRuntimeWithConfig(wazero.NewRuntimeConfigCompiler().WithWasmCore2())

_, err = wasi_snapshot_preview1.Instantiate(context.Background(), w.runtime)
if err != nil {
b.Fatal(err)
}
Expand All @@ -44,7 +45,7 @@ func initWasm(b interface {
return getStringImpl(ptr)
}

w.modules[1], err = runtime.NewModuleBuilder("env").
_, err = w.runtime.NewModuleBuilder("env").
ExportFunction("abort", func(msg, file, line, column int32) {
var m string
m += fmt.Sprint(`msg:`, __getString(msg))
Expand All @@ -55,7 +56,7 @@ func initWasm(b interface {
}).
ExportFunction("emscripten_notify_memory_growth", func(_ int32) {
}).
Instantiate(context.Background())
Instantiate(context.Background(), w.runtime)
if err != nil {
b.Fatal(err)
}
Expand All @@ -65,12 +66,12 @@ func initWasm(b interface {
b.Fatal(err)
}

compiledWasi, err := runtime.CompileModule(context.Background(), wasifile, wazero.NewCompileConfig())
compiledWasi, err := w.runtime.CompileModule(context.Background(), wasifile, wazero.NewCompileConfig())
if err != nil {
b.Fatal(err)
}

w.mainModule, err = runtime.InstantiateModule(context.Background(), compiledWasi, config)
w.mainModule, err = w.runtime.InstantiateModule(context.Background(), compiledWasi, config)
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -114,7 +115,7 @@ func initWasm(b interface {
}

type WasmWazero struct {
modules [5]api.Closer
runtime wazero.Runtime
mainModule api.Module
input uint64
output uint64
Expand Down Expand Up @@ -143,10 +144,5 @@ func (w *WasmWazero) Run(s string, v ...uint64) ([]uint64, error) {
}

func (w *WasmWazero) Close() error {
for _, m := range w.modules {
if m != nil {
m.Close(context.Background())
}
}
return w.mainModule.Close(context.Background())
return w.runtime.Close(context.Background())
}

0 comments on commit 023ef9c

Please sign in to comment.