Settings

Theme

Compilation of JavaScript to WASM, Part 2: Ahead-of-Time vs. JIT

cfallin.org

93 points by cfallin a year ago · 8 comments

Reader

_m1x6 a year ago

The real issue is that you cannot access the DOM via WASM.

Also the previous article is here[0].

[0]: https://news.ycombinator.com/item?id=37849310

  • laurencerowe a year ago

    That doesn’t really have anything to do with this article which is about running JS quickly on server wasm runtimes.

  • lll-o-lll a year ago

    Can you explain this a little more? This is for running JS server side right? So why would there be a DOM? Is the issue that JS libraries or other things you would be using assume a DOM?

  • davexunit a year ago

    This type of comment shows up on seemingly every thread about wasm and it is so tiresome. Wasm can't do any I/O unless the host passes the module a capability to do so. If you pass a module some DOM functions then it can access the DOM.

    • Waterluvian a year ago

      I’m curious though, does it gain meaningful access to the DOM in the case you described, or is it more just a proxy where it’s asking javascript, via some sort of channel, to manipulate the DOM?

      • sjrd a year ago

        It's a bit between the two, really. There are typically still JavaScript helpers in the middle, but not for the reason most people think. The remaining reason is that Wasm cannot perform JavaScript method calls (with a receiver object). It can only perform function calls (without receiver). So you need JavaScript helpers in the middle to translate between a calling convention that doesn't use `this`, only regular parameters, to another convention where one of those parameters becomes the receiver of a method call.

        Then that main reason has a number of declinations, like no JavaScript `new`, no field selection, etc. But you can work around all these things with similar "calling convention conversions".

        • remexre a year ago

          Maybe more importantly for performance, are those helpers inlinable into wasm?

          • pests a year ago

            At least in V8, wasm is handled by the same internals as javascript is. Its processed by the same optimization passes and turned into machine code by the same backend which generates the machine code for js.

            While I'm not sure how much cross-language optimization is being done, it sounds like these all reduce to the same concepts in the end and I don't think the performance impact will be as large as you think.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection