-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Minify imports and exports #7431
Conversation
… proper place [ci skip]
…ly worked with the hack we removed
… with the llvm wasm backend
… minify-imports-and-exports
# get the mapping | ||
SEP = ' => ' | ||
mapping = {} | ||
for line in out.split('\n'): |
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.
out.splitlines()
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.
Thanks, fixed.
"emscripten_memcpy_big": _emscripten_memcpy_big, | ||
"c": ___syscall54, | ||
"d": ___syscall140, | ||
"a": ___syscall146 |
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.
Is there meant to be two a
keys here? I see that's in the mapping below, but it would probably be clearer to have non-overwritten keys even just for the test?
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.
Thanks @curiousdannii, that wasn't intentional, I combined two testcases improperly. Fixing.
For background see emscripten-core#7414 This uses a new binaryen pass WebAssembly/binaryen#1719 to minify the import and export names in wasm, and then updates them in JS too. These are things that closure and other minfiers cannot minify themselves since they are on the js/wasm boundary, so it's up to us. This is kind of related to metadce, which also optimizes stuff on that js/wasm boundary. metadce finds things that can be removed entirely, while this new operation minifies the names of what remains. Turns out this is pretty useful, if you have lots of imports or exports. On BananaBread there are lots of GL calls, and we save 10% of JS size and 1% of wasm size. On Bullet we wrap classes for JS, which means calls to lots of functions, and we save 16% of JS size and 8% of wasm size. Much more than I expected! Some other minor fixes in this PR: * The emterpreter had some hacky way to add the extra globals it needs. Moved those to the proper place. This did require disabling a tiny part of the current test for the emterpreter (asm.js validation of raw emterpreter output, before integration back into the emscripten output), but that's not that important now - it was more useful when bringing it up initially. * Fix embind usage of dynamic dyncalls - they are on the Module object, we should not access Module.asm directly. * For CI testing this uses a temp tag in the binaryen port. Before landing we should tag binaryen and update that.
For background see #7414
This uses a new binaryen pass WebAssembly/binaryen#1719 to minify the import and export names in wasm, and then updates them in JS too. These are things that closure and other minfiers cannot minify themselves since they are on the js/wasm boundary, so it's up to us.
This is kind of related to metadce, which also optimizes stuff on that js/wasm boundary. metadce finds things that can be removed entirely, while this new operation minifies the names of what remains.
Turns out this is pretty useful, if you have lots of imports or exports. On BananaBread there are lots of GL calls, and we save 10% of JS size and 1% of wasm size. On Bullet we wrap classes for JS, which means calls to lots of functions, and we save 16% of JS size and 8% of wasm size. Much more than I expected!
Some other minor fixes in this PR:
Module.asm
directly.For CI testing this uses a temp tag in the binaryen port. Before landing we should tag binaryen and update that.