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
misc/wasm: js.TypedArrayOf is impossible to use correctly #31980
Comments
@neelance, @cherrymui, can we figure out a plan here for Go 1.13? Between stuff like this and #31812, it does seem like some API changes are needed. |
Yes, I agree that this is currently a bad situation. It is still unclear to me how WebAssembly will address this situation in the long run. With threads, the memory can grow at any time, even in parallel to the execution of JavaScript code. There is some discussion on WebAssembly/design#1271 but no consensus yet. The most safe approach right now would probably be to remove |
Change https://golang.org/cl/177537 mentions this issue: |
I have drafted the proposed solution here: https://golang.org/cl/177537 |
Have you considering my second proposal above? Namely: expand syscall/js.Value.Call (and Invoke) to accept Go slices, which are atomically wrapped in a TypedArray before being passed to the native side. I believe that's a strictly better option than explicit copy to/from JS:
where the Call atomically transfers the slice
|
The problem with the second approach is that it will still cause issues if the function that you are calling is using the typed array asynchronously. For example it would not have prevented #31702. I currently believe that there are quite some APIs like this. Your example with |
I'm working on a WebAssembly port of Gio, using WebGL for drawing. Some WebGL functions such as bufferData take a TypedArray for efficient data transfer. Calling bufferData from Go looks like this:
However, quoting from syscall/js:
CL 174304 works around one instance of this problem and replaced the typed array with a copy. Converting our bufferData call above in a similar way gives:
However, the above still results in rare crashes, leading me to suspect that there is no way to use TypedArrayOf correctly. I failed to produce a minimal test program, but I believe a modified version of Gio is enough to demonstrate the issue.
The relevant code is
The runtime.GC call is required to reproduce the crash every run, but in my case the crash happens even in the browser and without the runtime.GC call.
If I'm right, CL 174304 merely narrows the window for a crash, and #31812 is difficult to fix.
In order of preference, I propose one of:
CC @neelance.
The text was updated successfully, but these errors were encountered: