-
Notifications
You must be signed in to change notification settings - Fork 9
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
POC: Shrinking generated binary #223
base: main
Are you sure you want to change the base?
Conversation
So the problem is that binaryen (which contains the tool wasm-opt) supports only s-expressions in Webassembly code. So something like this is not understood:
This kind of syntax is used extensively in our code generation. The simple assignment of a clarity value to wasm variables for example works like this. |
What happens if you compile the WAT and then decompile it? Maybe it outputs in the "understood" format? |
No sadly, this is not how it works. You don't really compile Wat, you translate it to Wasm. |
it seems I made a false assumption. I tried compiling Wat using |
This is a POC trying to reduce the size of the generated binary.
The main issue in the generated binary is that the entire standard lib is copied inside.
As proposed in #119, I tried using wasm-opt, but not on the standard lib but on the generated Wasm.
It also has the advantage of applying other optimizations, like inlining, or precompute compile-time evaluatable expressions.
It works for small examples, such as
(+ 2 2)
, which results in a Wasm that contains the int 4 immediately. No more standard lib, and the result is precomputed.However, for most of our tests, it's a failure. It seems wasm-opt fails to parse our generated Wasm. It needs more investigations...