-
Notifications
You must be signed in to change notification settings - Fork 757
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
wasm-opt: Optimize for label count #5530
Comments
To limit the number of labels you'd need to do two things:
Both are doable but would take some serious work. Getting a wasm runtime to work seems easier to me. Do you know why it wasm3 hits a stack depth issue? Note that even on hello world there may well be one of those big binaryen/src/wasm-interpreter.h Lines 219 to 226 in 0596222
You can also try the wabt interpreter. |
Thanks for the reply @kripken !
This is not as easy as it sounds. Some functions are simply too big and complex, and there's a good chance to break it when attempting to do so.
This might be due to how it works https://github.com/wasm3/wasm3/blob/main/docs/Interpreter.md
Yeah I would need to find an interpreter that does not use the stack natively, and that can build to wasm, and hopefully 🤞 works. |
wasm3 has a quite small stack limits by default due to it applications (IoT) but it has ability to config this: https://github.com/wasm3/wasm3/blob/main/source/m3_config.h#L20 |
That's cool! unfortunately it still hits an overflow for some reason Edit: If I'm not mistaken, The alternative might be to try another interpreter |
@kripken is there a simple way to build the Binaryen interpreter into wasm? |
@iBicha There is already an emscripten port of binaryen, see the CMakeFiles. That emits wasm+JS. Porting to pure wasm with wasi-libc should be easy except that we use C++ exceptions, which they don't support yet, but they will eventually I hope. |
Thank you everyone for the help, I'll close this for now |
Looking for advice on a long shot.
The goal here is to run arbitrary wasm code on a Roku TV using brightscript
There is a tool that translates wasm modules to brightscript (wasm2brs). Brilliant!
The problem is that the brightscript runtime has limitations that wasm don't have.
One of these limitations is label count within a funciton (goto instruction labels).
Code fails to run as the label count gets closer to 256 (128 is a soft limit, and 256 is a hard limit, based on testing, see here)
For bigger projects, it's normal to a wasm function with hundreds of labels.
wasm-opt is being used to help with that (using
-O4
), but a lot of the times it's not good enough to keep the count level below the limit.My question is, is there a way to transform a wasm module, in a way that functions do not exceed a certain number of labels?
Another approach we tried is to translate a wasm runtime (e.g. wasm3) from wasm format to brightscript, and use that to load another wasm module. This approach does not hit the label count issue, but it faces another limitation of the BrightScript runtime, which is stack depth (even loading a hello world wasm leads to a stack overflow).
The text was updated successfully, but these errors were encountered: