-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix wasm loading in workers, and refactor async promise code #5011
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
Conversation
I realized as a nice benefit of this refactoring that we can get rid of the ugly preloading of the wasm binary into Module.wasmBinary in emcc. (And that made me notice some bugs in this PR, since it was just using the preloaded binary... fixed). |
WebAssembly.instantiate(getBinary(), info).then(function(output) { | ||
getBinaryPromise().then(function(binary) { | ||
return WebAssembly.instantiate(binary, info) | ||
}).then(function(output) { |
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.
Hey, since working on this, can you change the #if #endif in here to a #if #else #endif to avoid the "unreachable code" console warnings below?
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.
Good idea, fixing.
Module['printErr']('asynchronously preparing wasm'); | ||
addRunDependency('wasm-instantiate'); // we can't run yet | ||
WebAssembly.instantiate(getBinary(), info).then(function(output) { | ||
getBinaryPromise().then(function(binary) { |
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.
The main .html file is supposed to download the .wasm file. At this point, is it not possible that the .wasm file download is still in progress, but has not finished yet, and therefore getBinaryPromise()
will kick off a second parallel download redundantly?
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.
Not as it currently works - the html downloads the wasm binary before starting to do anything else. Another reason it's good to get rid of that thing ;)
return ret; | ||
} | ||
|
||
function getBinary() { |
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.
Do we still need this getBinary() function as well, or could we just have one getBinaryPromise() function that also contains the content of this function?
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.
We use it when we need synchronous access to it - for the interpreter, or when async compilation is off. Also, I think it's nice it's separate, conceptually.
ping @juj, see responses to comments above, i think this is good to go unless you have further issues. |
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.
This looks fine to me for now. I filed #5047 to talk about supporting both wasm and asm together well.
re-ping @juj |
Looks alright to me - the use of the |
Good to know about fetch, when they ship wasm on iOS we'll need to track that. |
Fixes #5005. Specifically, this