Skip to content
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

Merged
merged 18 commits into from
Nov 2, 2018
Merged

Minify imports and exports #7431

merged 18 commits into from
Nov 2, 2018

Conversation

kripken
Copy link
Member

@kripken kripken commented Nov 1, 2018

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:

  • 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.

# get the mapping
SEP = ' => '
mapping = {}
for line in out.split('\n'):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out.splitlines()

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Member Author

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.

@kripken kripken merged commit 841e796 into incoming Nov 2, 2018
@kripken kripken deleted the minify-imports-and-exports branch November 2, 2018 22:45
Beuc pushed a commit to Beuc/emscripten that referenced this pull request Nov 17, 2018
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants