-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Skip wasmBinaryFile initialization on pthread workers #21829
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
33fea95
to
3fd95b6
Compare
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.
Code lgtm but I think it's worth seeing why this increases code size. It seems like just moving code around shouldn't cause that, so maybe there is some specific issue that we can improve here.
Moving this code does seems to have some tiny effects on code size.. some positive but mostly minutely negative. Since this code is simply moved from top level to the inside of a function, with zero changes, I can only assume that is slightly confusing closure compiler. An alternative to move this code would be to instead wrap it in |
I tried looking at the generated code (after closure compiler was applied) both before and after this change but I'm struggling to come with any rationale for why it might regress. I took one same regression which is I've attached the result of clang-formatting the resulting JS files. Can you see where the differences are coming from. |
3fd95b6
to
8dcab60
Compare
I did some refactoring, and put this code into a function that can do early returns instead of branches. The code size effects are now almost all wins (especially with gz). |
Thanks, after adding some whitespace it is easier to flip back and forth between the files to see the differences, https://gist.github.com/kripken/286edabc866138d05716c2efbbd1cad4 The main issue (aside from code moving around, which does not affect size) is that in the new code the locateFile usage remains in a function, where it has a I see no reason for it not to be inlined in the new code. Perhaps closure is more careful about inlining into nested scopes. Or maybe it is because of the condition right before it - a little hard to see what that was before closure, but maybe you have some idea there. If not this is probably ok, but it's worth trying a bit to avoid a regression here I think. |
Ah, our last two comments raced. Your new code lgtm, and if gzip size is mostly a win then that seems fine. |
Perhaps because createWasm is already quote a large function closure chose not to inline. Or perhaps the inlining rules for top level code are differen to function-scope code? Anyway, after extracting the function the code size effects seem much better. |
8dcab60
to
56bc583
Compare
Delay the search for the wasm binary (e.g. using `locateFile`) so that it does not run on pthread workers (or weasm workers) where `Module.instantiateWasm` is set. The wasm file is always received via postMessage when running on the worker so we shouldn't ever be calling locateFile in this situation. See emscripten-core#21826 and emscripten-core#21827
56bc583
to
e09b6ba
Compare
The fact that we were calling
locateFile
in an attempt to find the wasm binary on each worker was confusing at best. The wasm file is always received via postMessage when running on the worker.See #21826 and #21827