3 ms·
I was also disappointed that this isn't included in the browsers given that it was designed to be very simple to parse and compile. So I tried as an exercise to
by stagas 5y ago
I was also disappointed that this isn't included in the browsers given that it was designed to be very simple to parse and compile. So I tried as an exercise to build such a compiler[0] and indeed it was much easier than I expected (with a few shortcuts of course, being a POC). It is just 5kb gzipped and it compiles to binary most of the WAT code out there and also quite fast, just a few ms. That said, I think writing WAT by hand is only helpful for very small critical hot code, anything more complex and IMO you need an abstraction of some sort.
[0]: https://github.com/stagas/wel https://github.com/stagas/wel
- TekMol 5y agoWow, all that code is needed to feed a string to WebAssembly.instantiateStreaming()? What does the code do? I was hoping there could be a trick like feeding a "blob:..." url to instantiateStreaming() or something. Since the bottleneck of a codebase typically is a single loop, I think it often would be a good approach to rewrite that one in Webassembly by hand.
- stagas 5y agoYou can inline the binary as base64 or simply a Uint8Array and instantiate it without having to fetch a wasm file. Many choose that approach as it also makes the library `import`-able in sync. The code I was pointing can be used to compile the WebAssembly Text format to binary and instantiate it afterwards on-the-fly, which is useful if you don't want a build step, so skipping the tooling(outside the browser) and also make edits which will then be compiled directly when the file executes. It's an option for experimentation mostly.
- TekMol 5y agoOoohh shit! Now I see that instantiateStreaming() does not accept webassembly in text format. So we need to ship a whole compiler to avoid a build step. Count me out :)
- stagas 5y agoYes, my point was that it's so trivial (and negligible in byte count size) to implement a compiler for the Webassembly text format, as the POC demonstrates, that it's curious why the browser isn't including one so that there isn't the need for extra tooling.