Skip to content
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

performance issue in browser environment #2207

Closed
storybehind opened this issue May 15, 2024 · 3 comments
Closed

performance issue in browser environment #2207

storybehind opened this issue May 15, 2024 · 3 comments

Comments

@storybehind
Copy link

Statement

I did a cross-compilation of Rust code to wasm and embedded into my Go application. After compiling my Go application with env GOOS=js & GOARCH=wasm and executing in browser environment, much slower performance is observed compared to my local environment.

Description

Please find the complete source code here: demo.zip

  1. demo.go - ImageRs.Convert() resizes an image by calling exported function in wasm using the runtime.
var (
	//go:embed image_rs.wasm
	imageWasm []byte

)

type ImageRs struct {
	ctx              context.Context
	runtime          wazero.Runtime
	compiledMod      wazero.CompiledModule
}

func (i *ImageRs) Convert(img []byte, width, height int) ([]byte, error) {
        ...
}
  1. main.go - provides js wrapper
func thumbnailWrapper() js.Func {
       ...
}

func main() {
	js.Global().Set("thumbnail", thumbnailWrapper())
	<-make(chan struct{})
}
  1. demo.wasm is produced on executing CGO_ENABLED=0 GOOS=js GOARCH=wasm go build -o demo.wasm . in root folder of the project.

  2. On opening demo.html instantiates demo.wasm.

Screenshots

Benchmark shows it takes less than a second to execute in my local env while it takes minutes in browser environment.

benchmark-go demo-browser

Environment (please complete the relevant information):

  • Go version: [1.22.0]
  • wazero Version: [1.7.2]
  • Host architecture: [amd64]
  • Runtime mode: [compiler]
@ncruces
Copy link
Collaborator

ncruces commented May 15, 2024

You're comparing running (a small Rust) Wasm binary by:

  1. using wazero to compile it to native amd64 assembly and running that;
  2. running the entire Go runtime, plus the wazero Wasm interpreter, inside another Wasm runtime.

TLDR: running a Wasm interpreter inside browser Wasm is slow.

Why do you want to do that?

@storybehind
Copy link
Author

Why do you want to do that?

This is part of SDK which is cross-compiled for use in few platforms including web. Due to limited support for the required functionality in Go, SDK uses wasm compiled from rust library and wazero runtime.

It seems like I'm complicating. Is there an alternate way that would work?

@mathetake
Copy link
Member

Sorry, essentially this is the issue with interpreter performance which is not the scope of the project.

@mathetake mathetake closed this as not planned Won't fix, can't repro, duplicate, stale May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants