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

Building standard.wat could use wasm-opt #119

Open
Acaccia opened this issue Oct 11, 2023 · 2 comments
Open

Building standard.wat could use wasm-opt #119

Acaccia opened this issue Oct 11, 2023 · 2 comments
Labels
enhancement New feature or request optimization

Comments

@Acaccia
Copy link
Collaborator

Acaccia commented Oct 11, 2023

Currently, standard.wat has a lot of functions (even basic ones) that calls subfunctions in their execution.

For example,

  • add-int and add-uint call the generic add-int128.
  • mul-int calls mul-uint, which calls mul-int128.
  • sha256-buffer calls multiple functions to keep it simple and clean.
  • ...

Problem is that those calls add up, and could become expensive. A simple solution here would be to run wasm-opt -O4 after the compilation from wat to wasm.

wasm-opt is a tool from binaryen, which is a part of the official Webassembly organization.

wasm-opt exists as a CLI tool, but exists also as a crate here: wasm-opt. This crate is (at the time of writing) two versions below the official tool.

@cylewitruk
Copy link
Member

As long as we can run our test suite against the optimized version and ensure that nothing "broke" in the process then I think that sounds like a good idea, assuming it doesn't affect size negatively too much (since the current theory is compiling the stdlib into each individual Clarity contract).

@Acaccia
Copy link
Collaborator Author

Acaccia commented Dec 20, 2023

I tried to add a wasm-opt pass in the generated code in #223, and it has issues that I describe more in that PR.

I still believe that this is useful, for the quantity of free improvements it brings: https://github.com/WebAssembly/binaryen#binaryen-optimizations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request optimization
Projects
Status: Status: 📋 Backlog
Development

No branches or pull requests

3 participants