6 ms·
Wazero: The zero dependency WebAssembly runtime for Go developers
- deleted 4y ago[deleted]
- mftb 4y agoThis looks pretty awesome, zero deps! I was wondering how I was gonna host other languages in my Go programs, this is a contender.
- Cthulhu_ 4y agoYou may want to consider not doing so; why host other languages if you can either write Go code, or write what your Go program does in said other languages? See also https://boringtechnology.club/ https://boringtechnology.club/
- ctvo 4y agoIt's pretty rude to walk around blasting a presentation at folks. You have no idea what their other requirements are. What if they need arbitrary user submitted code to be sandboxed and don't want to deal with cgo utilizing other wasm runtimes? Wazero seems pretty boring and perfect.
- oxplot 4y ago> why host other languages Here's an example: I recently finished building https://subzo.com.au https://subzo.com.au which allows customizing and ordering 3D models. The way the model's cost, volume and other attributes are calculated needs to be done both on the frontend (for speed) and on the backend (to validate). Backend is in Go and we can't practically run Go in the browser. So instead, I wrote the calculation snippets in JavaScript (which runs natively in the browser) and ran them on the backend on a JavaScript VM library written in Go [1]. [1]: https://github.com/robertkrimen/otto https://github.com/robertkrimen/otto
- mftb 4y agoHosting Go in Go is kind of an interesting idea! I enjoyed what I found on boring technology club and in general I agree, shipping is happiness, but! That's on the job. Outside of work I also do a bunch of stuff and there I do, uh... whatever. The point being that my personal projects are all about doing things I just wouldn't do at work, too much hassle. Anyway, I enjoyed the link.
- brancz 4y agoI happen to work on a lot of profiling and debugging tools and I’ve been wondering if the wasm spec has included anything about the “debugability” of wasm binaries. After a quick scan of the table of contents I couldn’t find it but I’d be curious to hear from anyone who might know. I fear that with an explosion of wasm runtimes (this looks super cool but also I think the 4th or 5th wasm runtime I’ve noticed) that debugability will be a nightmare if it’s not in the spec.
- lazyresearcher 4y agoWhat features exactly are you looking for? I have only used emscripten but you can compile debug builds and step through the code in the browser's inspector.
- brancz 4y agoI don't know enough about wasm runtimes, but for example JIT runtimes like nodejs (or JVM via perf-map-agent [0]) allow writing out debug infos via the Linux Kernel JIT-Interface [1], which debuggers and profilers can then pick up to symbolize stack traces. Not saying that it has to be the Linux JIT perf-map interface, but it'd be nice if it's something implementors of the runtimes kept in mind (not implying that they're not, I just haven't read anything). [0] https://github.com/jvm-profiling-tools/perf-map-agent https://github.com/jvm-profiling-tools/perf-map-agent [1] https://github.com/torvalds/linux/blob/master/tools/perf/Documentation/jit-interface.txt https://github.com/torvalds/linux/blob/master/tools/perf/Doc...
- miloignis 4y agoThat looks similar to how I profile my webassembly in wasmtime: https://docs.wasmtime.dev/examples-profiling-perf.html https://docs.wasmtime.dev/examples-profiling-perf.html , so that might be what you're looking for! It works pretty well. Wasmtime also has this page on debugging with supported debuggers when the webassembly was compiled with debug information: https://docs.wasmtime.dev/examples-debugging.html https://docs.wasmtime.dev/examples-debugging.html
- 4y ago
- deleted 4y ago[deleted]
- Shadonototra 4y agoSo far Zig, Odin and Go are the best languages for WASM C/C++ is a solid choice too thanks to EMSCRIPEN, but it is very slow to compile, and is not very clean solution dotnet is just too big for WASM rust is too complicated slow to program with
- moonchrome 4y agoThis is a WASM runtime/interpreter written in Go - not a Go compiler/runtime for WASM.
- mamidon 4y agoI've heard about wasm native gc for years. How can I see the actual status of the proposal? I'm not sure if they're actually working on it or blocked for some reason
- adrianfcole 4y agoThere's a proposals repo [1] that tracks the status of features like GC. According to that, GC is phase 2, which is prototyping [2]. To get to the finish line, implementations including at least 2 browsers need to happen (this is a Web standard, so there's some browser bias in the process). It is not straight forward to see who and what are implementing a proposal, especially if not tracked in the roadmap [3]. Best advice I could give for now is to watch the proposal repo [4], or just wait. It may be a while on this one. [1]: https://github.com/WebAssembly/proposals https://github.com/WebAssembly/proposals [2]: https://github.com/WebAssembly/meetings/blob/main/process/phases.md#2-proposed-spec-text-available-community--working-group https://github.com/WebAssembly/meetings/blob/main/process/ph... [3]: https://webassembly.org/roadmap/ https://webassembly.org/roadmap/ [4]: https://github.com/WebAssembly/gc https://github.com/WebAssembly/gc
- kaba0 4y agoGo has a runtime that has to be included, with GC running alongside the app. So no, it is not at all a good fit for Wasm, until the latter’s GC proposal gets finalized.
- dendellion 4y agoHow do y'all feel about Google shuting down your app by simply suing you over patents from the license?
- cyberpunk 4y agoIt’s Apache licensed…
- dendellion 4y ago...with a revokable patent grant.
- philderbeast 4y agoonly under very very very specific circumstances, that require you to take action rather then them being able to revoke it at will.
- dendellion 4y ago
- miloignis 4y agoIn addition to the creators of the project not being Google, it might be worth pointing out that most of the controversy happened when React switched away from Apache 2, not to it. See https://en.wikipedia.org/wiki/React_(JavaScript_library)#Licensing https://en.wikipedia.org/wiki/React_(JavaScript_library)#Lic...
- maxloh 4y agoWhat happened?
- justincormack 4y agoThis project is by Tetrate not Google.
- pbronez 4y agoCould this be used to deploy Go CLI programs as web apps? I haven’t worked with WASM before, but it seems like you should be able to sniff the CLI definition and expose the arguments and flags as basic web components / widgets.
- shantnutiwari 4y agoGotty can already do that
- adrianfcole 4y ago(wazero maintainer) no this doesn't really help with that. This runs wasm in Go, regardless of which language compiled to wasm. TinyGo [1] is the most popular option to compile Go into wasm, and they have some instructions for web browser embedding. [1] https://tinygo.org/docs/guides/webassembly/ https://tinygo.org/docs/guides/webassembly/
- pbronez 4y agoAh, thanks for the clarification!
- vvern 4y agoI’d love to see benchmarks.
- adrianfcole 4y ago(from wazero maintainer) we run benchmarks [1] on every commit! Depending on host and CI weather, we sometimes don't win [2] (click the Run make.check thingy) [1] https://github.com/tetratelabs/wazero/tree/main/internal/integration_test/vs https://github.com/tetratelabs/wazero/tree/main/internal/int... [2] https://github.com/tetratelabs/wazero/runs/6472382559?check_suite_focus=true https://github.com/tetratelabs/wazero/runs/6472382559?check_...
- skybrian 4y agoLooks like the compiler includes support for amd64 and arm64 code generation. It's unclear if you can compile WASM to assembly at runtime and invoke it? If so, it might be a viable way to implement plugin support.
- adrianfcole 4y ago(wazero maintainer) The default implementation will compile WASM to assembly not at runtime, but AOT (during Runtime.CompileModule). This allows more consistent performance and also more errors to materialize before a function call occurs. Compilation is automatic and also transparent (via mmap not files you configure), so you don't need to do anything special. waPC [1] (used by some things like kubewarden) is an example of a plugin system, and its go integration [2] is one of the few things currently using wazero. It also integrates with alternatives such as wasmer and wasmtime, so you can look at the code to see how things are different. We were intentionally hush about the project as we finish version 1.0, so weren't pushing for a lot of integrations, rather serving early adopters. Hence, wapc-go is currently the main victim of our api ;) hope this helps! [1] https://wapc.io/ https://wapc.io/ [2] https://github.com/wapc/wapc-go https://github.com/wapc/wapc-go
- skybrian 4y agoTo clarify the terminology, by AOT do you mean that the WASM needs to be compiled as part of the build of the Go executable that uses it, or just that it gets compiled before running the WASM code?
- adrianfcole 4y agonope this is all under the scenes. We formerly called this JIT, which was inaccurate but removed this confusion. Calling it AOT is more precise, but people ask this question. win some you lose some I guess! Anyway, if you use `wazero.NewRuntime()` magically it redirects to `wazero.NewRuntimeCompiler()`[1]. When the compiler is in use, all the native stuff happens automatically and you don't need to change your binary based on the wasm you use. This is actually neater than it seems as embedded compiler is goroutine safe, meaning you can compile modules concurrently. https://pkg.go.dev/github.com/tetratelabs/wazero#NewRuntimeConfigCompiler https://pkg.go.dev/github.com/tetratelabs/wazero#NewRuntimeC...
- irq-1 4y agoNeat! Few questions: whats the compiled size? Any performance numbers? How is it easier to access functions and types from WASM to Go, and vice versa?
- adrianfcole 4y ago(wazero maintainer) thanks for asking the questions! I'll answer them below. First as TL;DR; then more explained. TL;DR; > whats the compiled size? wazero adds less than 2MB to your binary with no strings attached. > Any performance numbers? yes, but unlike most projects we don't add numbers to our README > How is it easier to access functions and types from WASM to Go, and vice versa? Take a look at our examples, and let us know how easy it is? [5] Long: > whats the compiled size? wazero adds less than 2MB to your binary with no strings attached. Because wazero doesn't rely on CGO, you have the simplicity of counting only the size of the binary. In other words, there are no potentially large shared libraries you need to count, and certainly no glibc needed. I made this example [1], which is the a basic calculater, and it makes a 3.3MB binary (go 1.18.2) slightly larger in Docker (3.4MB via FROM scratch). It used to be 3.1MB until we added WebAssembly 2.0 support which is really quite big. Meanwhile I think the smallest Go binary would be 1.7MB or so. > Any performance numbers? yes, but unlike most projects we don't add numbers to our README. README numbers are instantly out of date. We might publish on cron or something, since people seem really interested. We run benchmarks on every commit[2], and the results vary, but not in surprising ways. The most accurate benchmark is allocation [3], though most people seem to only benchmark math functions. allocation is more like what your real code would do, ex an envoy filter changing a header. I saved results from a recent run to save you some clicking [4]. Sometimes wasmer beats us in one of the benchmarks, and that's with their default config. Besides speed of calling, we pay attention to both the performance and safety of instantiating a wasm module. Instantiation is when you create a new sandbox. Granted, this is a new project and speed wise we have work to do, but at least concurrency works. So you can safely use the same runtime and create a new sandbox even per request. If your wasm is small that could happen in <1ms. > How is it easier to access functions and types from WASM to Go, and vice versa? Take a look at our examples, and let us know how easy it is? [5] We've worked on this quite a bit, and hope that we are doing ok on it. Basically wasm has "export" functions (sometimes called externs), and we have an api.Function[6] interface for calling regardless of who defined it. We have a ModuleBuilder[7] which is how you define functions in go. These are explained by our examples [5]. For us, we mainly designed based on how we felt things could be in Go, feedback from users and also comparing against how others do it. Particularly, we looked at wapc-go [8] to ensure our API felt the leanest possible to achieve the same goal. [1]: https://gist.github.com/codefromthecrypt/edb33284354d592dc6056b9b7263872f https://gist.github.com/codefromthecrypt/edb33284354d592dc60... [2]: https://github.com/tetratelabs/wazero/blob/main/.github/workflows/commit.yaml#L136 https://github.com/tetratelabs/wazero/blob/main/.github/work... [3]: https://github.com/tetratelabs/wazero/blob/main/internal/integration_test/vs/bench_allocation.go https://github.com/tetratelabs/wazero/blob/main/internal/int... [4]: https://gist.github.com/codefromthecrypt/48877abc4b3ba5ceca12b312926b1e0a https://gist.github.com/codefromthecrypt/48877abc4b3ba5ceca1... [5]: https://github.com/tetratelabs/wazero/tree/main/examples https://github.com/tetratelabs/wazero/tree/main/examples [6]: https://pkg.go.dev/github.com/tetratelabs/wazero/api#Function https://pkg.go.dev/github.com/tetratelabs/wazero/api#Functio... [7]: https://pkg.go.dev/github.com/tetratelabs/wazero#ModuleBuilder https://pkg.go.dev/github.com/tetratelabs/wazero#ModuleBuild... [8]: https://github.com/wapc/wapc-go/tree/master/engines https://github.com/wapc/wapc-go/tree/master/engines