FaaS in Go with WASM, WASI and Rust
eli.thegreenplace.net
eli.thegreenplace.net
Wazero is awesome, I wish them luck and hope to use it, but I would use wasmtime for most everything until it gets a lot further along.
First, wazero is awesome, thanks for building it!
I saw initial steps of a Cranelift Wazero backend in your organization. Any plans or ETAs around this?
Very experimental! No ETAs yet but we're considering a few strategies for the optimizing compiler
A couple examples of this: * https://github.com/jerbob92/go-pdfium-wasm * https://github.com/ncruces/go-sqlite3
More here: https://wazero.io/community/users/
Note that often times a lot of work is porting because not all tools build well to wasm. This would apply for any runtime as we're just running the standard with some special extensions for emscripten, wasi etc.
Call common wasm code across 16 different programming languages using our SDKs.
I applaud it! He's right. It is.
Except of course in reality FAAS and WASM and all implementations have less language support than cgi-bin ...
- JVM;
- LLVM;
- WebAssembly; or
- Something else entirely?
There's no real multi-module linking right now, which means that for I.e. a runtime library you'll end up 1. Compiling the runtime library to wasm 2. Editing that wasm code in place to add your generated code (that uses runtime functions). And that's a bit hacky.
Fingers crossed for the component model to solve this, but LLVM is definitely much more mature (and can compile down to WASM, and vice versa). In the end, for toy projects, both are great fun, and WASM is definitely more "cutting edge".
Btw. I do recommend using Rust for playing with WASM. Wazero is awesome (and it's what I used) but all the experimental features of WASM that are very useful (like 64 bit memory support) are not available here yet. Wasmtime and wasmer are probably the most popular engines (other than V8), both are in Rust, and both have a lot of experimental features implemented and activatable. Their bindings in other languages aren't as complete in that regard.
Use all of them, in no time you'll stick with one that fits you.
(The problem space... of music theory. Or programming. Or "just writing our app" but in a way that generates reusable modules that are constrained to be small, well-defined in terms of types and functionality, and easy to test.) And learning to play the instruments all together in some kind of harmony, one that you can even type check, is just... chefs kiss
Some people think Ruby is the wrong choice, and others are building successful businesses on it as a foundation. Did they make this choice because of subjective tastes, or for practical reasons?
(And you can do this with Wasm, implement compilers in your Ruby framework in a way that's fairly unobtrusive, to take advantage of apps that were compiled in another language that isn't C... and likely to net you some type of benefits if not performance benefits – but the constraints are interesting. Did I mention that Wasm doesn't seem to have a string type, unless you count WASI?)
I mentioned Ruby because I'm giving a lightning talk on this topic this week Tuesday at GitOpsCon and a bigger talk at OSS Summit (one on Wednesday and another on Thursday...)
It's called "Exotic Runtime Targets"
Ruby and Wasm on Kubernetes and GitOps Delivery Pipelines
There's also "Microservices and WASM, Are We There Yet?"
$ echo salaboy | wazero run ruby-3.2.0.wasm -ne 'print "Hello "; print'
Hello salaboy
Of course getting and gems etc gets weird in wasm..
Anyway, thanks to VMware labs for publishing interpreter wasm builds, people can play around. https://github.com/vmware-labs/webassembly-language-runtimes...
Random, but enjoy.
Probably not justified, but that’s a hassle I’d want to avoid if I had any plans to support Unicode.
Plenty of people liked it then I agree, can’t really understand why, because the simplicity argument just moved the complexity into libraries.
Java predates ISO C++, and the UNIX world was a mess of K&R C, and half backed ISO C89.
Design patterns were invented for Smalltalk and C++, as much as people like to blame Java for them.
Depends on what you want your toy language to do and what sort of runtime support you'd like to lean on.
JVM is pretty good for a lot of script-y languages, does impose overhead of having a JVM around. Provides GC, Threads, Reflection, consistent semantics. Tons of tools, libraries, support.
WebAssembly is constrained (for running-in-a-browser safety reasons) but then you get to run your code in a browser, or as a service, etc, and Other People are working hard on the problem of getting your WA to go fast. That used to be a big reason for using JVM, but it turns out that Security Is Darn Hard.
I have used C in the (distant) past as an IL, and that works up to a point, implementing garbage collection can be a pain if that's a thing that you want. C compilers have had a lot of work on them over the years, and you also have access to some low-level stuff, so if you were E.G. trying to come up with a little language that had super-good performance, C might be a good choice. (See also, [Wuffs](https://github.com/google/wuffs), by Nigel Tao et al at Google).
A suggestion, if you do target C -- don't work too hard to find isomorphisms between C's data structures and YourToyLang's data structures. Back around 1990, I did my C-generating compiler for Modula-3, and a friend at Xerox PARC used C as a target for Cedar Mesa, and Hans used it in a lower-level way (so I was mapping between M-3 records and C structs, for example, Hans was not) and the lower-level way worked better -- i.e., I chose poorly. It worked, but lower-level worked better.
If you are targeting a higher-level language, Rust and Go both seem like interesting options to me. Both have the disadvantage that they are still changing slightly but you get interesting "services" from the underlying VM -- for Rust, the borrow checker, plus libraries, for Go, reflection, goroutines, and the GC, plus libraries.
Rust should get you slightly higher performance, but I'd worry that you couldn't hide the existence of the borrow checker from your toy language, especially if you wanted to interact with Rust libraries from YTL. If you wanted to learn something vaguely publishable/wider-interesting, that question right there ("can I compile a TL to Rust, touch the Rust libraries, and not expose the borrow checker? No+what-I-tried/Yes+this-worked") is not bad.
I have a minor conflict of interest suggesting Go; I work on Go, usually on the compiler, and machine-generated code makes great test data. But regarded as a VM, I am a little puzzled why it hasn't seen wider use, because the GC is great (for lower-allocation rates than Java however; JVM GC has higher throughout efficiency, but Go has tagless objects, interior pointer support, and tiny pause times. Go-the-language makes it pretty easy to allocate less.) Things Go-as-a-VM currently lacks:
- tail call elimination (JVM same)
- don't ever construct a pointer to Object+sizeof(Object) (i.e., to the first byte past the end) (JVM same)
- defined semantics for racy programs that don't use atomics (structures can tear; there is a race detector, use it). (JVM same-ish; racy programs suck)
- integer overflow checking (JVM same)
- consistent conversion from +/-FPInf to integers,
- if you're not careful about expressing floating point a+b*c, you'll get the platform multiply-add rounding
- signaling/quiet NaN representation follows the platform
Some of these are on my list of Would-Be-Nice to fix, but that doesn't mean they will happen, because there are O(zero) people using Go as a VM, as far as I know, so their problems have zero weight. Tail-call-elimination in particular would be hard, and I see no substantial benefit in solving the pointer-past-end problem (it's a minor issue in our own code generation, and we deal with it).
Fastly provides an API via a rust crate that you use to build your edge (CDN) logic with. They also provide a local development cli that can run these WASM bundles with.
I keep wanting a flow like this to work for faas python data science sandboxed serving, esp @ scale -- python interpreters talking to cpython kernels and one day GPU passthrough -- but the experience leaves me wondering about wasm on the backend in general
Basically, coldstart overhead + overall runtime overhead + inability to use GPU mean it'll be awhile yet for something you want to run. The former may be partly about pyodide (but not entirely?), but the latter seems to be about wasm
Comparatively, firecracker VMs seem to solve a lot here. Though still a lot you have to role out on your own to actually scale untrusted code here vs just say fargate
I feel like I must be missing something.. am curious.