team icon indicating copy to clipboard operation
team copied to clipboard

Figuring out a proper JS fallback

Open CryZe opened this issue 6 years ago • 9 comments

I feel like we should have some reasonable solution for supporting older browsers. So far I haven't really found a good solution so that's why I'm bringing it up here. Also once we have a good solution, we should probably document it.

CryZe avatar May 11 '18 15:05 CryZe

AFAIK there's two major solutions here:

  1. Use wasm2asm in Binaryen. The wasm-bindgen repo has an example of this and has a mode for the wasm2es6js tool which runs wasm2asm.
  2. Use a wasm emulator in the browser, mentioned here.

Neither of these solutions is robust (AFAIK) in the sense that wasm2asm still has a lot of shortcomings and I'm not sure if there's much progress towards emulating wasm in the browser through JS.

I'd personally see wasm2asm as the best route forward here, but it'd certainly require a lot more love before we could officially recommend it I think

alexcrichton avatar May 11 '18 18:05 alexcrichton

There's also asmjs-unknown-emscripten (though obviously that has the overhead of emscripten)

Pauan avatar May 12 '18 00:05 Pauan

I'll do more concrete benchmark on the JavaScript interpreter inplementation. What would be acceptable performances?

xtuc avatar May 12 '18 08:05 xtuc

@xtuc It will vary from project to project. Some projects may be fine with a 100x slowdown, others obviously will find that unacceptable.

Pauan avatar May 12 '18 15:05 Pauan

I should be free to continue work on wasm2asm soon if that would be useful to the community.

tlively avatar May 12 '18 16:05 tlively

Alright, I've dug a bit further into this and this seems to be the current state:

  1. There's a WebAssembly interpreter called webassemblyjs, but that straight up just crashes completely on a stack overflow on Internet Explorer.
  2. Compiling wasm to asm.js via wasm2asm doesn't work for any actual large project as a lot of instructions aren't implemented right now.
  3. While asmjs-unknown-emscripten is a solution, I'm trying to actually switch away from emscripten as it hugely reduces the amount of potential contributors to the project as people don't really want to compile full on LLVM just to contribute to the project. That's a huge turn off.

CryZe avatar May 12 '18 16:05 CryZe

@CryZe I should have mentioned it before sorry. I'm the author of webassemblyjs.

First, could you please open an issue with the crash? Thanks. Currently the interpreter doesn't support the full instruction set and on my few microbenchmarks It's arround 50 times slower than native.

On a side note, is that I'd like to take advantage of asm.js semantics in the interpreter.

xtuc avatar May 12 '18 21:05 xtuc

binaryen's wasm2js (ne wasm2asm) has been getting a lot of love (mostly from @alexcrichton) recently. I think this is what we should recommend going forward.

With that in mind, would anyone like to write a section of the book about making JS fallback work via wasm2js?

fitzgen avatar May 25 '18 21:05 fitzgen

  • I guess this is a duplicate of https://github.com/rustwasm/book/issues/12?
  • How different would that section be from the corresponding example in the wasm-bindgen guide, i.e. do you think this is still necessary?
  • Would it make sense to support this workflow directly from wasm-pack, say, with a flag like --target=bikeshed-old-browser?

jrvidal avatar Mar 14 '19 21:03 jrvidal