-
Notifications
You must be signed in to change notification settings - Fork 0
Fix benchmark workflow: drop goloader, fix proto panic, fix wazero module exit #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,6 @@ import ( | |
| "plugin" | ||
| "runtime" | ||
| "testing" | ||
| "unsafe" | ||
|
|
||
| gocplugin "github.com/GoCodeAlone/go-plugin" | ||
| gcyaegiinterp "github.com/GoCodeAlone/yaegi/interp" | ||
|
|
@@ -18,7 +17,6 @@ import ( | |
| "github.com/hashicorp/go-hclog" | ||
| hashicorpplugin "github.com/hashicorp/go-plugin" | ||
| "github.com/natefinch/pie" | ||
| "github.com/pkujhd/goloader" | ||
| "github.com/tetratelabs/wazero" | ||
| "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" | ||
| "github.com/traefik/yaegi/interp" | ||
|
|
@@ -182,44 +180,6 @@ func RandInt(i int) int { return rand.Int() }` | |
| }) | ||
| } | ||
|
|
||
| func BenchmarkGoloaderRandInt(b *testing.B) { | ||
| linker, err := goloader.ReadObjs([]string{"goloader.o"}, []string{"main"}) | ||
| if err != nil { | ||
| b.Error(err) | ||
| return | ||
| } | ||
|
|
||
| run := "main.RandInt" | ||
|
|
||
| symPtr := make(map[string]uintptr) | ||
| err = goloader.RegSymbol(symPtr) | ||
| if err != nil { | ||
| b.Error(err) | ||
| return | ||
| } | ||
|
|
||
| b.Run("goloader", func(b *testing.B) { | ||
| codeModule, err := goloader.Load(linker, symPtr) | ||
| if err != nil { | ||
| fmt.Println("Load error:", err) | ||
| return | ||
| } | ||
| runFuncPtr, ok := codeModule.Syms[run] | ||
| if !ok || runFuncPtr == 0 { | ||
| fmt.Println("Load error! not find function:", run) | ||
| return | ||
| } | ||
| funcPtrContainer := (uintptr)(unsafe.Pointer(&runFuncPtr)) | ||
| runFunc := *(*func() int)(unsafe.Pointer(&funcPtrContainer)) | ||
| for i := 0; i < b.N; i++ { | ||
| _ = runFunc() | ||
| } | ||
|
|
||
| os.Stdout.Sync() | ||
| codeModule.Unload() | ||
| }) | ||
| } | ||
|
|
||
| func BenchmarkWazeroRandInt(b *testing.B) { | ||
| wasmFile, err := os.ReadFile("wazero.wasm") | ||
| if err != nil { | ||
|
|
@@ -233,11 +193,23 @@ func BenchmarkWazeroRandInt(b *testing.B) { | |
|
|
||
| wasi_snapshot_preview1.MustInstantiate(ctx, runtime) | ||
|
|
||
| module, err := runtime.Instantiate(ctx, wasmFile) | ||
| compiledModule, err := runtime.CompileModule(ctx, wasmFile) | ||
| if err != nil { | ||
| fmt.Println("failed to compile module:", err) | ||
| return | ||
| } | ||
|
|
||
| // WithStartFunctions() with no arguments skips the auto-start (_start) | ||
| // entry point so the WASI module stays alive for repeated RandInt calls. | ||
| // Without this, TinyGo's _start calls main() and then proc_exit(0), | ||
| // closing the module before any benchmark iterations can complete. | ||
| cfg := wazero.NewModuleConfig().WithStartFunctions() | ||
| module, err := runtime.InstantiateModule(ctx, compiledModule, cfg) | ||
| if err != nil { | ||
| fmt.Println("failed to instantiate module:", err) | ||
| return | ||
| } | ||
| defer module.Close(ctx) | ||
|
|
||
| b.Run("wazero", func(b *testing.B) { | ||
| randIntFunction := module.ExportedFunction("RandInt") | ||
|
Comment on lines
214
to
215
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this benchmark, compile/instantiate failures are handled by printing and returning, which makes
go testsucceed while silently skipping the wazero sub-benchmark. That can reintroduce the "missing benchmark results" failure mode (or leave README rows stale). Prefer failing the benchmark (e.g.,b.Fatalf/b.Fatal) so CI clearly reports the problem.