binaryen icon indicating copy to clipboard operation
binaryen copied to clipboard

Add a pass to remove exports from the WASM bundle

Open loganek opened this issue 1 year ago • 4 comments

This is helpful when e.g. there's a WASM shared library with all possible functions exported but the application only needs a subset of those exports. Removing exports in that case will enable further optimizers to remove more code from the file.

loganek avatar Aug 16 '24 19:08 loganek

@kripken based on my tests the pass is executed before passes for removing dead code, but I wasn't sure if that's just coincident or a stable behavior. Could you confirm if that's the case (otherwise users would have to call wasm-opt twice to get all the optimizations) or is there anything I could do to make this explicit? Many thanks.

loganek avatar Aug 16 '24 19:08 loganek

Before getting into details here, please see this wiki page:

https://github.com/WebAssembly/binaryen/wiki/Pruning-unneeded-code-in-wasm-files-with-wasm-metadce#example-pruning-exports

wasm-metadce can prune exports, perhaps that is enough for your use case?

kripken avatar Aug 16 '24 19:08 kripken

Thanks for sharing. This sort of solves the problem I'm trying to solve; one difference here is that for wasm-metadce you need to define reachable nodes, whereas this pass does it other way around (you define exports that you don't need). I think it's a bit more scripting to define all reachable functions in my case, but I can definitely live with that. Up to you then whether you want to merge it or close.

loganek avatar Aug 16 '24 19:08 loganek

I see, thanks. I don't feel strongly, then, since it somewhat different. Maybe let's keep it open and see if other people comment that they could benefit as well - if so, I think we should land it.

kripken avatar Aug 22 '24 21:08 kripken