Skip to content

Way of using binaryen without optimization passes #7566

@kormanowsky

Description

@kormanowsky

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.

Activity

kripken

kripken commented on May 2, 2025

@kripken
Member

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

kormanowsky commented on May 2, 2025

@kormanowsky
Author

@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

kripken commented on May 2, 2025

@kripken
Member

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

kormanowsky commented on May 4, 2025

@kormanowsky
Author

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @kripken@kormanowsky

      Issue actions

        Way of using binaryen without optimization passes · Issue #7566 · WebAssembly/binaryen