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

wasm-tools optimization #7340

Open
andreaTP opened this issue Feb 28, 2025 · 2 comments
Open

wasm-tools optimization #7340

andreaTP opened this issue Feb 28, 2025 · 2 comments

Comments

@andreaTP
Copy link

Hi 👋 and thanks for the awesome project!

Today I have been playing with wasm-tools and hitting a number of limits/corner cases, I'd like to share what I have found and any help is highly appreciated.

The wasm file to reproduce the steps is here.

I try to summarize the main issues I have encountered so far:

  • wasm-opt takes a very long time to process the module, I'm on a 16 cores x86 machine:
$ time wasm-opt -Oz wasm-tools.wasm -o wasm-tools-opt.wasm
wasm-opt -Oz wasm-tools.wasm -o wasm-tools-opt.wasm  296.77s user 1.06s system 540% cpu 55.132 total
  • after the optimization, it generates a function type with 680 parameters (type 90) the maximum expressible in Java is 255 and this is the first time we hit this limit
  • I attempted to use wasm-split but I'm failing to find documentation about the "profile", do you have a link to spare?

What I would like to achieve:

  • split out the wasm module into more easily processable modules
  • reduce the functions size so that we don't hit JVM limits

As said, any help is very welcome!

@tlively
Copy link
Member

tlively commented Feb 28, 2025

I ran this optimization with BINARYEN_PASS_DEBUG=1 to get timings for each of the passes, and it looks like the longest-running pass by far is inlining-optimizing. Using -Os instead of -Oz makes this a little faster, but also shrinks the module a little less. The -Os version does not have that function with hundreds of parameters.

I also ran with BINARYEN_PASS_DEBUG=3 to dump the intermediate state after each pass is run and found that the pass that introduces the functions with hundreds of parameters is merge-similar-functions. We should update that pass to avoid situations like that. On the Web, the limit on the number of function parameters is 1000, but perhaps we can have Binaryen use the 255 limit or make it configurable.

You can read more about the workflow of using wasm-split here: https://emscripten.org/docs/optimizing/Module-Splitting.html. Some of that documentation is Emscripten-specific, but it should give you an idea of how to use wasm-split directly. You can also look at the commands run by our wasm-split tests to get an idea of how it works.

@tlively
Copy link
Member

tlively commented Feb 28, 2025

#7341 fixes MergeSimilarFunctions so it no longer produces more than 255 parameters.

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

No branches or pull requests

2 participants