WebAssembly brings extensibility to network proxies
opensource.googleblog.com
opensource.googleblog.com
Are other projects moving from Lua (or other embedded scripting languages) to WebAssembly? What are the benefits of compiling an extension to WASM rather than writing it in Lua?
Be it Rust, C, C++, Typescript, and I bet there will be a Lua interpreter in WASM at some point too.
It will be more flexible, and possibly more performant.
If it's going to encompass the possibility to hook into the JS side GC engine, this might not be implemented at all in headless Wasm applications, and so you wouldn't be able to use the GC'd languages on those platforms, just C(++)/Rust. Which is not very attractive compared to the easier / safer high level languages most programmers are used to.
Also, As someone familiar with Rust, it is a very high-level language. It’s zero-overhead features make it a bit of a steep learning curve, but you rarely need to drop to its low-level unsafe features.
That being said, incorporating it into a new WASM environment probably means doing a lot of low-level stuff.
Performance: Other than the need for trampolines between the host and the wasm code, WebAssembly runs at essentially full speed. Lua is fast for an language built on dynamic types and dynamic dispatch - which is to say, quite slow.
Security: The reference Lua implementation was not designed for untrusted code; there have been various attacks where loading invalid bytecode could grant arbitrary execution. Using a format designed for executing untrusted code has real advantages there.
Lua with JIT is very fast even compared to statically typed, compiled languages.
The bottleneck doesn’t seem to be dynamic types or dispatch but rather relying on garbage collection. Another example of this would be Julia.
Admittedly WASM is typically targeted by languages like C and Rust, but I wouldn’t put Lua in the same, general performance category as for example python or most other dynamically typed languages with dynamic dispatch.
Wasm is 1.5x - 11x faster depending on a browser and such.
Here is a very technical 2019 paper comparing Wasm against native compilation. Wasm is 1.5x slower than bare metal https://www.usenix.org/system/files/atc19-jangda.pdf
The second is about benchmarking C, I suspect it doesn't give us a lot of information in this question either.
* https://github.com/bytecodealliance/wasmtime
* https://wasmerio.github.io/wasmer/c/runtime-c-api/
The underlying implementation of each is written in Rust.
(Recently I also discovered there's a "micro VM" too: https://github.com/bytecodealliance/wasm-micro-runtime)
The official WASM C API is still WIP but wasmtime targets it directly: https://github.com/WebAssembly/wasm-c-api/
Not sure if Wasmer is aiming for compatibility with the official WASM C API currently.
From my experience, Wasmtime's C support is probably best described as "under-documented but functioning".
I haven't implemented anything with Wasmer.
My impression is that Wasmer may offer a higher level API than Wasmtime but not sure if it counts as "drop in" yet.
Part of the reason why I ended up going with Wasmtime was...I kinda forgot Wasmer existed. :D But also I do like that they're targeting what will hopefully become a standard API--but I think that results in a lower level API than what is most "friendly" for starting out.
Been meaning to make this embedded Wasmtime C API example--created while figuring things out--public after tidying it up a bit more but... well, I just now made it public, as is (it at least has a ReadMe now :D ): https://gitlab.com/RancidBacon/wasm-embed-test :)
Also, this is one option for test compiling C to WASM without setting up a tool chain: https://wasdk.github.io/WasmFiddle/
Some of my notes from development so far: http://www.labradoc.com/i/follower/p/notes-webassembly#20200...
Edit: Grammar. Add & then move micro WASM VM link.
Opcode costs help to incentivize efficient code.
ewasm/design /README.md [2] links to the complete WebAssembly instruction set. [3]
[1] https://ewasm.readthedocs.io/en/mkdocs/determining_wasm_gas_...
[2] https://github.com/ewasm/design/blob/master/README.md
[3] https://webassembly.github.io/spec/core/appendix/index-instr...