-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/compile: document that TypedArrays are not pinned in memory #29355
Comments
Hmm, this is unfortunate. Calling With the current state of WebAssembly the only solution that I see is to not pass the typed array directly but instead wrap it in a custom helper that can create the correct typed array on demand and the user is not allowed to keep a reference to this typed array. This is quite cumbersome. The threads proposal might save us: It used a |
Ah, I see, thanks for the explanation! I was able to get the wrapper approach to work, but boy is it a lot of cruft. Also, will this leak the The threads proposal is indeed interesting. Until the proposal lands, would it be possible to create a second, non-growing memory instance to be used as an arena to communicate over? |
The 128M number was arbitrary, and some tuning may be necessary to find an optimal number. This ends up triggering golang/go#29355, and thus requires the workaround suggested in that thread: construct a flyweight TypedArray each type the JS wants to mutate the slice. The workaround slows things down around 18% from ~39ms per document to ~46ms, but I have an idea for a workaround for _that_ (TODO in the code). Delete the Go1.12 port because it's not worth maintaining it at this early prototypal stage.
The 128M number was arbitrary, and some tuning may be necessary to find an optimal number. This ends up triggering golang/go#29355, and thus requires the workaround suggested in that thread: construct a flyweight TypedArray each type the JS wants to mutate the slice. The workaround slows things down around 18% from ~39ms per document to ~46ms, but I have an idea for a workaround for _that_ (TODO in the code). Delete the Go1.12 port because it's not worth maintaining it at this early prototypal stage.
Depends on your implementation. I'm not sure what you did.
I don't see a good way to make this work with Go's memory management. |
OK, fair enough. Thanks! |
I currently don't see anything worthwhile that we could do prior. You can still use typed arrays right now, you just shouldn't hold a reference to them from JavaScript. For example the way that the |
Does it make sense to add a line of documentation clarifying this ? |
Sure, why not. |
Change https://golang.org/cl/155778 mentions this issue: |
What version of Go are you using (
go version
)?What version of Node are you using?
Does this issue reproduce with the latest release?
Yes. This occurs at master, as well.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Created a js.TypedArray in a Go program running under wasm, and then mutated it in a JS callback.
What did you expect to see?
The TypedArray would be successfully mutated, which the Go program could subsequently inspect.
What did you see instead?
In some circumstances, I would get:
My suspicion is that the GC is moving the underlying byte arrays in times of memory pressure, because the easiest way to trigger this is to decrease the initial heap size, either using wams or by modifying asm.go.
Background
I'm doing this to keep a long-running Go-wasm process around and repeatedly call a Go function from JS, without leaking the input/output objects due to lack of cross-heap GC.
The code to reproduce it is at ampproject/amppackager#220 but requires a test file I haven't checked in -- if you're interested in running it, let me know and I'll add one.
Let me know if I'm holding it wrong and there's some simpler way of achieving my goal.
The text was updated successfully, but these errors were encountered: