binaryen icon indicating copy to clipboard operation
binaryen copied to clipboard

Way of using binaryen without optimization passes

Open kormanowsky opened this issue 8 months ago • 4 comments

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.

kormanowsky avatar May 02 '25 12:05 kormanowsky

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

kripken avatar May 02 '25 15:05 kripken

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

kormanowsky avatar May 02 '25 15:05 kormanowsky

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.

kripken avatar May 02 '25 17:05 kripken

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.

kormanowsky avatar May 04 '25 12:05 kormanowsky