5 ms·
Analyzing the Performance of WebAssembly vs. Native Code
- turbolent 11mo ago... in browsers. Which at best JIT compile. There are several WASM runtimes that AOT compile and have significantly better performance (e.g. ~5-10% slower). The title is highly misleading.
- astafrig 11mo agoIt’s not misleading to measure the performance of WebAssembly in a web browser.
- bjconlan 11mo agoYeah, but it's specifically testing things that implement against a posix API (because generally that's what "native" apis do (omiting libc and other os specific foundation libraries that are pulled in at runtime or otherwise) I would suspect that if the applications that linked against some wasi like runtime it might be a better metric (native wasi as a lib/vs a was runtime that also links) mind you that still wouldn't help the browser runtime... But would be a better metric for wasm (to native) performance comaparison. But as already mentioned we have gone through this all before. Maybe we'll see wasm bytecodes pushed through silicon like we did the Jvm... Although perhaps this time it might stick or move up into server hardware (which might have happened, but I only recall embedded devices supporting hardware level Jvm bytecodes). In short the web browser bit is omitted from the title.
- wffurr 11mo agoWebAssembly is neither web nor assembly. It’s a low level byte code format most similar to LLVM IR.
- pyrolistical 11mo agoJust means the browsers can catch up. Initially slower but then faster after full compilation
- padenot 11mo agoBrowsers have been doing (sometimes tiered) AOT compilation since wasm inception.
- chalcolithic 11mo agocould you please name them?
- wffurr 11mo agoWAMR (WebAssembly Micro Runtime), wasm2c in WABT (WebAssembly Binary Toolkit), Wasmtime.
- chalcolithic 11mo agothank you very much!
- icsa 11mo ago45% slower to run everywhere from a single binary... I'll take that deal any day!
- andyferris 11mo ago45% slower to run everywhere from a single binary... with less security holes, without undefined behavior, and trivial to completely sandbox. Its definitely a good deal!
- ben-schaaf 11mo agoNative code generally doesn't have undefined behaviour. C has undefined behaviour and that's a problem regardless of whether you're compiling to native or wasm.
- pron 11mo ago> without undefined behavior Undefined behaviour is defined with respect to the source language, not the execution engine. It means that the language specification does not assign meaning to certain source programs. Machine code (generally) doesn't have undefined behaviour, while a C program could, regardless of what it runs on.
- gishh 11mo agoThat which is old is new again. The wheel keeps turning… “Wait we can use Java to run anywhere? It’s slow but that’s ok! Let’s ride!”
- bloppe 11mo agoThere's a reason Java applets got deprecated in every browser. The runtime was inherently insecure. It just doesn't work for the web. Also, targeting the JVM forces you to accept garbage collection, class-based OO and lots of pointer chasing. It's not a good target for most languages. Java's pretty good, but wasm is actually a game changer.
- 11mo ago
- rlili 11mo agoThat it’s not even an order of magnitude slower sounds actually pretty good!
- ModernMech 11mo agoYeah, I've seen this when test Rust code compiled into native and wasm. I don't know about 45% though, I haven't measured it.
- vlovich123 11mo agoThis is pretty good actually considering the low hanging optimizer optimizations left and that the alternative is JS which generally performs 2-10x slower. I think vectorization support will narrow the aggregate difference here as a lot of SPEC benefits from auto vectorization if I recall correctly.
- PantaloonFlames 11mo ago45% slower means..? Suppose native code takes 2 units of time to execute. “45% slower” is??? Would it be 45% _more time?_ What would “45% _faster_” mean?
- tharakam 11mo agoI guess it is clearer if expressed like "Native application took only x% of WASM equivalent".
- huflungdung 11mo ago[dead]
- azakai 11mo ago0% slower means "the same speed." The same amount of seconds. 10% slower means "takes 10% longer." 10% more seconds. So 45% slower than 2 seconds is 1.45 * 2 = 2.9 seconds.
- oersted 11mo agoIt’s a fair point, that way of expressing it is always a bit confusing. Is it the original time plus 45%? Is it 45% of the original speed? I think it is easier to understand in terms of throughput. So 45% less work per unit of time, so 55% of the work.
- gjm11 11mo agoWhat looks like the relevant table has a summary line saying "geometric mean: 1.45x" so I think that in this case "45% slower" means "times are 1.45x as long". (I think I would generally use "x% slower" to mean "slower by a factor of 1+x/100", and "x% faster" to mean "faster by a factor of 1+x/100", so "x% slower" and "x% faster" are not inverses, you can perfectly well be 300% faster or 300% slower, etc. I less confidently think that this is how most people use such language.)
- degamad 11mo agoWhat would 300% faster mean? If the original process took 30 minutes to process 10 items, how long would the 300% faster method take?
- azakai 11mo agoThe data here is interesting, but bear in mind it is from 2019, and a lot has improved since.
- b_e_n_t_o_n 11mo ago45% slower seems pretty decent considering they use a wasm kernel they developed to mimic the unix kernel so they can run non-modified unix programs inside the browser. It's actually pretty impressive that they did this, and even more impressive that it works and like another commentator said, is not even an order of magnitude slower. I'm more interested in 1) usages of wasm in the browser that don't involve running unmodified unix programs and 2) wasm outside the browser for compile-once-run-anywhere usecases with sandboxing / security guarantees. Could it be the future for writing native applications? Languages like Kotlin, C#, Rust, as well as C/C++ etc support wasm quite well. Could we see that be a legitimate target for applications in the future, if the performance gap was closer to 10%-ish? I would personally prefer running wasm binaries with guaranteed (as much as possible ofc) sandboxing compared to raw binaries. edit: it's from 2019, there have been significant improvements made to wasm since then.
- wmf 11mo agowasm outside the browser for compile-once-run-anywhere usecases with sandboxing / security guarantees Please just use Docker in a microVM or whatever. It's 0% slower and 100% more mature.
- rowanG077 11mo agoSetting up docker and a microVM is orders and orders of magnitude harder and less ergonomic then using your browser. These are not at all interchangeable.
- wmf 11mo agowasm outside the browser
- unoti 11mo ago> Please just use Docker in a microVM or whatever. It's 0% slower and 100% more mature. Wasm has different characteristics than docker containers and as a result can target different use cases and situations. For example, Imagine needing plugins for game mods or an actor system, where you need hundreds of them or thousands, with low latency startup times and low memory footprints and low overheads. This is something you can do sanely with wasm but not with containers. So containers are great for lots of things but not every conceivable thing, there’s still a place for wasm.
- fanf2 11mo ago(2019)
- gnabgib 11mo ago(2019) Popular in: 2019 (250 points, 172 comments) https://news.ycombinator.com/item?id=20458173 https://news.ycombinator.com/item?id=20458173 2020 (174 points, 205 comments) https://news.ycombinator.com/item?id=19023413 https://news.ycombinator.com/item?id=19023413
- baudaux 11mo agoI have built Fibonacci wasm wasi executable for Rust. When I execute it in https://exaequos.com https://exaequos.com (with wex runtime under development), it is faster than the native app on my MacBook
- jedisct1 10mo agoReally depends on the application. WebAssembly can't use SIMD intrinsics and CPU-specific instructions besides simd128 and what the compiler can do. At least for cryptography, WebAssembly can be very slow and can hardly provide any guarantee against side channels.