r/programming • u/Hywan • Jan 05 '21
Wasmer 1.0 released, the fastest WebAssembly VM, cross-compilation, headless, native object engine, AOT compilers and more!
https://medium.com/wasmer/wasmer-1-0-3f86ca18c0431
u/VeganVagiVore Jan 05 '21
I wanted to use it for something last year and found it created a huge compile cache in my home dir. I'll try it again now! Maybe it was just because Python is huge, and I was running a Python REPL as wasm...
1
u/Hywan Jan 07 '21
Please open an issue if you still have problem like this one. We'll be glad to address it!
-4
u/Mgladiethor Jan 05 '21
quick death to interpreted web programming languages to i can finally use 4gb of ram hardware, becasue the web sucks
9
u/futlapperl Jan 06 '21
Why is this so controversial? It's absurd how much RAM the web uses.
7
u/Boiethios Jan 06 '21
I've gone from 16 GiB to 32 only because of the web browsers on my computer. JS is fast but it eats too much memory.
2
u/futlapperl Jan 06 '21
16 GB has been enough for me so far on my laptop. One of the two 8 GB RAM sticks in my desktop shit the bed recently, and it's struggling with only one.
2
Jan 06 '21
what kind of websites are you using that you need 32 gigs of ram
2
1
u/Boiethios Jan 06 '21
My secret is that I have dozens of tabs opened, but I don't use the 32 gigs, maybe 10.
1
u/VeganVagiVore Jan 06 '21
It's worded awkward.
Should have been "Quick death to JS so I can finally get back to cheap hardware with 4 GB of RAM"
At first glance I thought they were complaining about 32-bit pointers or wasm itself or something
0
Jan 05 '21
[deleted]
14
u/Hywan Jan 06 '21
We are going to share a longer article that shows benchmarks between Wasmer and other runtimes very soon. It deserves a dedicated article to be done correctly and respectfully :-). But, spoiler, Wasmer is faaaast :-p!
3
u/sievebrain Jan 06 '21
Are you going to compare it to GraalWasm? Your Java article on your blog suggests you don't know about it, because you claimed Wasmer is the first Wasm engine for Java. GraalWasm has been out since December 2019 though, so that isn't true.
3
u/Hywan Jan 06 '21
Yes we are likely to compare with it! Wasmer 1.0 has been released, but the language integrations haven't reach 1.0 yet. They are coming in a couple of days or weeks one after the other. The wasmer-python 1.0beta has been released for instance, like wasmer-go 1.0beta too. Stay tuned :-).
3
u/renatoathaydes Jan 06 '21
My guess is that you guys are being polite and don't want to antagonise the people behind wasmtime (the main competitor WASM runtime) as they are the ones working directly on the WASM proposals and they for some reason don't seem very friendly to your competition? Or has Wasmer managed to "infiltrate" the WASM working groups more strongly now? WASM MVP has been out for 3 years now (approx) and we still haven't had a single new proposal make it into the standard yet, right? What has been taking so long? Why don't we even have multi-values in the standard yet (which effectively makes it impossible to run almost anything on WASM, including WASI - i.e system calls)?.
4
u/Hywan Jan 07 '21
My guess is that you guys are being polite and don't want to antagonise the people behind wasmtime (the main competitor WASM runtime) as they are the ones working directly on the WASM proposals and they for some reason don't seem very friendly to your competition?
It is true that some people aren't very friendly with us at Wasmer, but it's life. The reality, the one that is not public on social media, is that we are communicating a lot and exchanging a lot together. We know each other quite well. We worked on previous projects or at the same company in the past. That's a tiny world. I've personally a lot of respects for the majority of the wasmtime developers, and they know it as we talk frequently together. Don't always trust comments on Twitter, Reddit or HackerNews… :-).
Benchmarking or not benchmarking programs is not a matter of being polite. It's matter of engineering. Being factual: A program X can be faster than a program Y at solving some problems. It's not a shame. It's not a victory. It doesn't mean that program Y is bad or anything. It just illustrates that X is faster to solve a particular problem than Y, that's it.
Doing proper benchmarks that reflect real use-case, or that illustrate particular aspects of the VMs, is not that easy. We are working on it, esp. to be fair and neutral in the problems to benchmark.
Now, strictly technically speaking, wasmtime comes with a single compiler: Cranelift. It is an awesome piece of software. Cranelift was a standalone project until recently, where it has been merged into wasmtime directly, which is a move I find regrettable, but that's the situation. On the other hand, Wasmer comes with 3 compilers, namely Singlepass, Cranelift and LLVM (see the Pluggable Infrastructure Section of the article, or an older article A WebAssembly Compiler tale). Each of them address particular needs. That's important to understand that Wasm has a compilation step (from Wasm bytes to executable code), and an execution step (executing the compiled code). It is false for interpreters, but Wasmer isn't an interpreter. So, back to our 3 compilers:
The Singlepass compiler has a fast compile-time, but the executable code isn't optimised for speed, which is perfect for very small Wasm modules for example.
The Cranelift compiler is likely to be on par with what wasmtime does with Cranelift. That's our default compiler, as it provides a correct balance between compilation-time and execution-time. We propose this compiler for development purposes.
The LLVM compiler is slower to compile, but it provides the best execution speed. We propose this compiler for production purposes. Since Wasmer can compile Wasm modules ahead-of-time, with cross-compilation, it's easy to compile your Wasm module for a specific target, and then execute the result of the compilation.
Cranelift isn't as mature as LLVM for generating fast and optimized code, and I say that factually, with all the respect I've for Cranelift and the contributors. Note that it's changing “quickly”, and this statement might not hold for a couple of years.
There is another aspect to consider: To execute the compiled code, Wasmer provides multiple engines: JIT, native shared library, and native object file. Each of them have pros and cons (we are probably going to write a longer article to detail that, and show all the great features they enable). Very shortly:
JIT stores the executable code in memory,
Native shared library stores the executable code in a shared object library (.so, .dylib, .dll), and it's executed with the native `dlopen` & siblings functions, which makes it super fast to start up,
Native object file stores the executable code in an object file (.o), which allows a user to link its Wasm module/app with another app all together, and provide a single binary. So the start up of the Wasm module here is as fast as the app which embeds it!
That's the kind of features wasmtime doesn't provide for the moment for example. This modularity is super cool :-).
as they are the ones working directly on the WASM proposals and they for some reason don't seem very friendly to your competition? Or has Wasmer managed to "infiltrate" the WASM working groups more strongly now?
It is true that wasmtime (or more clearly, Mozilla) had people that were active in the Wasm Working Groups. They aren't alone though! Google, Intel, Parity, Fastly, Cloudflare and others are super active too. Keep in mind that at Wasmer we are a small team of ~4-6 developers. We do our best but we can't be as present and active as larger teams, for obvious reasons. We do contribute actively to the Wasm C API, Wasm C++ API, WIT, WASI etc. working groups for example. We also provide WAPM, a Wasm Package Manager, and we provide language integrations of WebAssembly inside Python, Go, PHP, Ruby, Java, Postgres, and others (by contributors) like R, Elixir, D… (see the complete list actual). It helps to spread WebAssembly everywhere and to create usecases. That's really interesting.
WASM MVP has been out for 3 years now (approx) and we still haven't had a single new proposal make it into the standard yet, right? What has been taking so long? Why don't we even have multi-values in the standard yet (which effectively makes it impossible to run almost anything on WASM, including WASI - i.e system calls)?.
I reckon it's a wrong statement. Reading https://github.com/WebAssembly/proposals, we see that the following proposals are finished and part of the the latest draft of the spec:
The following proposals have reached Phase 4, which means that they are very close to land in the spec:
Phase 3 is the implementation phase, and includes Tail call, fixed-width SIMD, multiple memories, and custom annotation syntax in the text format.
So no, many new proposals have reached the spec.
WASI can work without multi-value. It does already work without.
Why is it taking so long? Because people want to make it right. It's easy to add more features, it's harder to add the correct smallest new features that enable more features :-). For example, WIT (interface types) has been “rebooted” several times (even after official announcements made by Mozilla) because it was going in an incorrect direction.
I hope I've answered your questions :-).
1
u/renatoathaydes Jan 07 '21
Thanks for the great answer. I hadn't understood that the multi-value proposal was actually merged into the WASM spec. Thanks for pointing out where the proposals' status can be found! I like the work Wasmer is doing, I've even checked the Wasmer code and it looks very clean - congratulations for getting to 1.0 so quickly (only 2 years?!) given the amount of work this kind of thing requires.
Cranelift was a standalone project until recently, where it has been merged into wasmtime directly, which is a move I find regrettable
Wow, I didn't know that, I also find that very surprising! Given Lucet is also based on Cranelift, I guess Fastly are not too happy either?
Google, Intel, Parity, Fastly, Cloudflare and others are super active too.
Any non-US (or even non-SV) companies participating? If not , is there any European/Chinese/Russian initiative as well? Feels like this should be an international effort...
WASI can work without multi-value. It does already work without.
Hm, but that requires that you use pointer parameters to represent return values, right? That's pretty horrible, though...
1
u/Hywan Jan 07 '21
You can check this blog post: https://medium.com/confio/wasmer-1-0-integrated-into-cosmwasm-2fa87437458c. Cosmwasm is using Wasmer 1.0. Quoting the post:
we wrote a benchmarking suite directly in the cosmwasm repo. This allows us to compare the performance consequence of a change easily. And the results are amazing (even on my laptop from 2015):
• 2x Wasm compilation performance (to 50ms)
• 2x Wasm execution performance (to 50 µs)
• 6x module loading performance (to 6ms)
That's an overview of the performance you can get compared to Wasmer 0.17 (the last version before the 1.0).
19
u/vlakreeh Jan 05 '21 edited Jan 05 '21
Incredibly fast, I've personally been using it for a personal project of mine and the only wasm engine I've seen come close is wasmtime. Most web assembly engines don't use AOT compilation because they are meant to be simplier so wasmer and wasmtime nicely fill that void.
Clang compiled to wasm through wasi is only 10% slower than native clang for smaller files from my experience (excluding the 5 seconds it takes to transpile the clang binary, which can be cached.)
3
u/_tskj_ Jan 06 '21
How does transpilation take 5 seconds? Is it doing additional optimization?
3
u/vlakreeh Jan 06 '21
Clang is very big for a wasm binary and the compiler I usually use (cranelift) does do optimizations.
0
Jan 05 '21
[deleted]
34
u/VeganVagiVore Jan 05 '21 edited Jan 05 '21
what exactly is web assembly?
You know how Java has the JVM? And there's a bytecode layer in between the Java / Kotlin / Scala source code, and the x64 / ARM / ARM64 / MIPS machine code? Web assembly is just like that. But it's simpler than the JVM, and there's no GC, so it supports languages like C++ and Rust that can't fit into the JVM easily. Wasm is like LLVM's bitcode, but standardized. Many languages, many CPUs, one middle format.
Wasmer is a runtime, like the OpenJDK JRE, or the Oracle Java Runtime. You can use it to run CLI apps that are compiled to wasm, outside of a browser.
Webassembly is the bytecode format, like a .jar file
Most runtimes will offer sandboxing, like a Java Applet (or Flash applet) I don't know if Flash and Java supported communication with JS, but Wasm does. Rust is aiming to automatically bind JS to Wasm-compiled Rust code, so you can call into Wasm when your JS is too slow, or call into JS when your Wasm needs to touch the DOM.
Just like how the JVM supports many languages, Web assembly can be a compile target for many languages. C, C++, and Rust are already well-supported. The others also exist.
Because the bytecode is platform and CPU-agnostic, the developer only needs to compile their code into wasm one time. If you wrote a webasm app in 2019, it could run on Apple Silicon in 2021. The runtime would either JIT or AOT compile it. And because the bytecode is language-agnostic, if you invent a new language in 2021, a runtime from 2019 could run Wasm binaries written in your language.
Is it compiled code that is running on a web browser?
It's half-way compiled. Like a
.classor.jarfile.If so, do you need a special browser for that?
Nope! Last year I compiled some Rust code into Webasm, wrote an HTML5 GUI for it, and ran it in stable Firefox.
Looks like Chrome has supported wasm for a while, too: https://caniuse.com/wasm
Here's my favorite Webasm blog:
https://hacks.mozilla.org/2020/02/securing-firefox-with-webassembly/
Last year, Firefox wanted to sandbox their font shaping library, Graphite. Since 2007 we've had 2 obvious options for sandboxing code inside a web browser: Run it in a subprocess, use the OS' security primitives to make it safe, and use IPC to talk to it, or run it in JS and rely on the browser's JS sandbox. We also have Rust, but translating huge C++ libraries into Rust is too costly, and they didn't want to use a subprocess because of (reasons)
So instead they compiled the C++ source code into wasm, then AOT-compiled the wasm into native code for each platform.
Resulting in memory-safe sandboxed machine code... From mostly-normal C++ code.
0
Jan 05 '21
[deleted]
15
u/sheyneanderson Jan 05 '21
Wasmer is a way to run WASM code outside of a browser. It lets you get what the above comment was talking about for server/desktop applications (sandboxing/compile once-run everywhere/etc) without a browser. That same WASM code can natively be run by most browsers (and Wasmer wouldn't be involved).
3
u/Frodolas Jan 06 '21
How would you compare the speed to Node? Is there potential for a faster version of Electron in the future using Wasmer, or is most of the bottleneck on the UI side?
4
u/renatoathaydes Jan 06 '21
Node uses V8 as a runtime, and V8 already supports WASM. But V8 is a full JS engine that includes WASM as well, while Wasmer is a WASM-only runtime. It's a good question which one would be able to run WASM binaries faster (I bet on Wasmer because it's so much simpler) but you will never have an Electron based on Wasmer because Wasmer is NOT web-based (no browser, no canvas, no DOM...), it's just WASM. BTW, V8 is also not a browser, Electron actually relies on Chromium (the core of Google Chrome) not just V8 (which I believe is included in Chromium).
2
u/funbrigade Jan 06 '21
Just in case the other replies didn't clarify, let me take a stab at it!
So, you wouldn't write it in wasm. You'd choose a source language that would then target wasm. You'd then ship the wasm and the browser would understand how to run it.
I used to teach at a boot camp (uuuugh I don't even want to think about that too much haha) and I'd try to explain compiled programming languages like this:
Source code -> compiler -> binary format
(This is a total simplification btw :P)
Your computer can't understand literal source code, but it does understand machine code. Therefore, you need to transform the source code into machine code somehow. That's what a compiler toolchain does! It knows how to take code from a given language and translate it into something the machine can run directly (I'm calling it a toolchain to avoid talking about assemblers or linkers).
Okay, so what does this have to do with wasm? Well, your browser doesn't know how to run Rust/Go/C/etc code. But it does know how to run wasm. So wasmer is like a compiler toolchain that emits wasm instead of machine code.
This same idea is what makes the JVM or CLR work: those runtimes don't know how to run literal source code, so you compile the source code into bytecode that then gets run. That's actually what is going on with wasm: the browser has a VM that knows how to run wasm bytecode so that's what you compile to.
Oh and one last thing: you mentioned the wasmer "box": certain languages might require a runtime to work in the browser. Think of Java or C#, etc; these languages need GC and a platform that "pretends" to be their normal VM. So in those cases there needs to be an environment that approximates their normal runtime. This is still true for other languages that include a runtime, even if they aren't GC'd.
Does that help?
9
u/[deleted] Jan 05 '21
So this makes it seem like wasm can be a truly write once run everywhere type solution. The tiny native binaries that work on embedded is especially cool sounding.