3

Is the JS VM in browsers as efficient as the webassembly interface?

If it is not, then why don't browsers transpile JS to webassembly?

I realize JS does do JIT in a lot of browsers (all?).

Comments
  • 1
    Great questions but above my and devRant's pay grade.
  • 0
    I don't get this part

    > If it is not, then why don't browsers transpile JS to webassembly?

    Is it not the opposite? WebAssembly is transpiled into JavaScript?
  • 1
    I don't know how webassembly works but probably because transpiling cost + running webassembly is slower than just running js. Idk
  • 1
    ̶I̶ ̶d̶o̶n̶'̶t̶ ̶g̶e̶t̶ ̶t̶h̶i̶s̶ ̶p̶a̶r̶t̶

    ̶>̶ ̶ ̶I̶f̶ ̶i̶t̶ ̶i̶s̶ ̶n̶o̶t̶,̶ ̶t̶h̶e̶n̶ ̶w̶h̶y̶ ̶d̶o̶n̶'̶t̶ ̶b̶r̶o̶w̶s̶e̶r̶s̶ ̶t̶r̶a̶n̶s̶p̶i̶l̶e̶ ̶J̶S̶ ̶t̶o̶ ̶w̶e̶b̶a̶s̶s̶e̶m̶b̶l̶y̶?̶

    ̶I̶s̶ ̶i̶t̶ ̶n̶o̶t̶ ̶t̶h̶e̶ ̶o̶p̶p̶o̶s̶i̶t̶e̶?̶ ̶W̶e̶b̶A̶s̶s̶e̶m̶b̶l̶y̶ ̶i̶s̶ ̶t̶r̶a̶n̶s̶p̶i̶l̶e̶d̶ ̶i̶n̶t̶o̶ ̶J̶a̶v̶a̶S̶c̶r̶i̶p̶t̶?̶

    I got it all mixed up.
  • 3
    JS is often JIT compiled to bytecode that runs in the browser.

    Webassembly is an assembly language that targets directly the VM.

    The main reason why WASM is more efficient that JIT JS is types: JS needs to do a lot of runtime checks that aren't needed in ahead of time compiled languages (like WASM
  • 2
    @rantydev probably also because of the ahead-of-time-compilation.
  • 1
    @rantsauce exactly. It would be impossible to ahead of time compile a dynamic language :)
  • 0
  • 2
    This post has an interesting benchmark:

    https://javascript.plainenglish.io/...
Add Comment