Skip to content

Way of using binaryen without optimization passes #7566

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
kormanowsky opened this issue May 2, 2025 · 4 comments · May be fixed by #7569
Open

Way of using binaryen without optimization passes #7566

kormanowsky opened this issue May 2, 2025 · 4 comments · May be fixed by #7569

Comments

@kormanowsky
Copy link

I would like to use binaryen just to emit WASM modules without optimizations, Wasm2JS and so on. Is it possible to compile somewhat minimal amount of code for that? Did not find a quick way to do it.

@kripken
Copy link
Member

kripken commented May 2, 2025

If you do not specify optimizations, they will not run - what optimizations did you see happen that you didn't want?

(Note that wasm2js specifically does run some passes internally, as part of compilation.)

@kormanowsky
Copy link
Author

kormanowsky commented May 2, 2025

@kripken

No, optimisations themselves did not happen. It is just the compilation which takes longer due to compiling cpp files related to optimization passes.

What I did is I added the following to my CMakeLists.txt (I use CMake):

set(BUILD_TESTS Off)
set(BUILD_STATIC_LIB On) # I need a static lib, this is expected
set(BUILD_LLVM_DWARF Off)
set(BUILD_TOOLS Off)
set(ENABLE_WERROR Off)
add_subdirectory(third_party/dependencies/binaryen)
include_directories(third_party/dependencies/binaryen/src)

where third_party/dependencies/binaryen is where a submodule of this repo resides.

Then I launched cmake and did see the following:

Image

There are ~100 files which got compiled but seem related only to optimizations and emscripten and I did not use any of them. So I am wondering if there is a way to turn off the compilation of those files so that the whole process is faster and the output file is less in terms of file size.

@kripken
Copy link
Member

kripken commented May 2, 2025

Oh, it sounds like you want to build Binaryen itself without optimizations enabled?

There isn't an option for that. You could probably hack up src/passes/CMakeLists, pass.cpp to remove passes you don't need, but it would be messy.

@kormanowsky
Copy link
Author

kormanowsky commented May 4, 2025

Just created a PR to allow configuring this via SKIP_OPTIMIZATIONS option in CMakeLists and a C++ macro.
Changes I made led to decrease in compilation time by 3-4 minutes on my machine and in file size by ~60 MB.

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 a pull request may close this issue.

2 participants