Skip to content

Add a rollup plugin for tree shaking Emscripten output. #23964

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

brendandahl
Copy link
Collaborator

Rollup has built in tree shaking which can inform the plugin which exports are no longer used. If those exports correspond to wasm exports they can potentially be removed from wasm file too.

Overview:
While the modules are parsed, we collect info about the exports before any tree shaking occurs to build a map from ESM export name to Wasm export name and info about the local function name within the JS e.g. _foo.

During bundle generation rollup provides a list of exports that are removed. We then try to match the removed exports to Wasm exports. However, they all cannot simply be removed though since they may be used internally in the file still. A new list of the used wasm exports is generated and passed to wasm-metadce to remove any unused exports.

Note: there are a lot more things we could do there, but this seemed like a good stopping point. It also shows that even for specific output, tree shaking is hard to do soundly for dynamically loaded wasm.

Rollup has built in tree shaking which can inform the plugin which exports
are no longer used. If those exports correspond to wasm exports they can
potentially be removed from wasm file too.

Overview:
While the modules are parsed, we collect info about the exports before any
tree shaking occurs to build a map from ESM export name to Wasm export
name and info about the local function name within the JS e.g. _foo.

During bundle generation rollup provides a list of exports that are
removed. We then try to match the removed exports to Wasm exports. However,
they all cannot simply be removed though since they may be used internally
in the file still. A new list of the used wasm exports is generated and
passed to wasm-metadce to remove any unused exports.

Note: there are a lot more things we could do there, but this seemed like
a good stopping point. It also shows that even for specific output, tree
shaking is hard to do soundly for dynamically loaded wasm.
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.

1 participant