Live data from Hacker News

Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code

usenix.org

121–130 of 212 posts

Re: Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code

#121

How much of this performance gap is due to the inherent limitations of the WebAssembly technology, and how much is due to it being relatively new? I.e., do we expect to see performance improvements similar to what we've seen in JavaScript over the last two decades? Or are we going to need better hardware to realize better performance?

Section 6.4 tries to answer this question.

> It is worth asking if the performance issues identified hereare fundamental. We believe that two of the identified issues are not: that is, they could be ameliorated by improved implementations. WebAssembly implementations today useregister allocators (§6.1.2) and code generators (§6.2.1) thatperform worse than Clang’s counterparts. However, an offlinecompiler like Clang can spend considerably more time togenerate better code, whereas WebAssembly compilers mustbe fast enough to run online. Therefore, solutions adoptedby other JITs, such as further optimizing hot code, are likely applicable here.

> The four other issues that we have identified appear to arise from the design constraints of WebAssembly: the stackoverflow checks (§6.2.2), indirect call checks (§6.2.3), andreserved registers (§6.1.1) have a runtime cost and lead to in-creased code size (§6.3). Unfortunately, these checks are nec-essary for WebAssembly’s safety guarantees. A redesigned WebAssembly, with richer types for memory and function pointers [23], might be able to perform some of these checksat compile time, but that could complicate the implementation of compilers that produce WebAssembly. Finally, a Web-Assembly implementation in a browser must interoperate witha high-performance JavaScript implementation, which mayimpose its own constraints. For example, current JavaScript implementations reserve a few registers for their own use,which increases register pressure on WebAssembly.

Re: Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code

#122

It's early days. Calm down. It will speed up.

The reserved registers may always be a problem. It reminds me of the people who complained about massive slowdown in games when Vista released. The games were so optimized to fit in a single page that the few new pieces of state in the window manager caused page thrashing.

For single-instance scenarios with a single memory, I think using a 0-based memory will be a lot more efficient than reserving a register for the memory base. That doesn't fly when a Wasm engine is embedded into an arbitrary C++ program, but for standalone scenarios this may be feasible.

Re: Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code

#123

So many comments here missing the point. As a developer, I can use wasm to ship a single binary that works on Windows, Mac, Linux, Android, and iOS. I can use the language that I want. I don't need to have Xcode, visual studio, android studio, or any other set of tools: you can reasonably build an app with your text editor and LLVM. And then, you can use my app by typing its address into your address bar. No installa…

Literally everything you said except the part about using the language you want has been true of Java for at least a decade. Everything old is new again.

Java... Are you kidding. The UI stack and distribution model is horrible compared to WebAssembly.

The resources available for HTML/CSS cannot be compared with JavaFX, Swing or whatever the other original stack was. And the Applets sandboxing was obviously so horrible everyone killed it. WA is amazing here copying the existing and already hardened JavaScript model.

Re: Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code

#124
post #98

Earlier quoted context omitted.

sure, you can compile an application, but if you want to target everyone, you have to do it on at least 3 architectures (linux, mac, windows) and as a user, i am either lucky if my architecture is supported, or i am scrambling to find an alternative. in my case i actually have all three. so when i see a new application i want to try, i check which one is best supported and then pick that. several apps run only on win…

> sure, you can compile an application, but if you want to target everyone, you have to do it on at least 3 architectures (linux, mac, windows) Is that really a big deal, though? From what I understand (and I could be wrong, so correct me if I am), most of the headaches involved in multi-platform development is the OS specific UI. Video games, for example, don't find porting to multiple architectures all that challen…

It really depends on how complex your code is and what you're targeting. For example, the V8 JavaScript engine has a ton of ifdefs depending on OS (Windows, Mac, Linux, Fushia), bitness (32 or 64), chipset (ARM, ARM64, PPC, x64, etc.) and combinations thereof. For example, see some of the defines in https://github.com/v8/v8/blob/master/src/common/globals.h#L1... and their uses throughout the codebase.

EDIT: I forgot Android, and all the compiler specific flags. (https://github.com/v8/v8/blob/master/include/v8config.h is probably a better reference).

Re: Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code

#125

So many comments here missing the point. As a developer, I can use wasm to ship a single binary that works on Windows, Mac, Linux, Android, and iOS. I can use the language that I want. I don't need to have Xcode, visual studio, android studio, or any other set of tools: you can reasonably build an app with your text editor and LLVM. And then, you can use my app by typing its address into your address bar. No installa…

Literally everything you said except the part about using the language you want has been true of Java for at least a decade. Everything old is new again.

Except you can run wasm on an iPhone.

I like Java but it's not like they didn't try Java applets. They really screwed the security model. I guess in that sense what the parent is asking for is actually not nearly as feasible as using the current web security model.

Re: Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code

#126
post #51

Please actually read the paper. As usual, the mean is a poor approximation of a distribution. This paper states repeatedly that it was able to reproduce the experimental results from the 2017 PLDI paper, which primarily used PolyBenchC as the suite. My team wrote that paper. We didn't cherry pick. The issue is mostly that we suck more on Spec2k6 than we realized. Since publishing that paper we do track Spec2k6 intern…

Thank you for the clarification. Some questions related to V8 perf:

1. WASM JS/Host calls seem to have a higher cost on chrome than FF [1][2]. Is that in your optimization roadmap?

2. Wasmer tracks V8 perf against other backbends, and the LLVM backend consistently outperforms V8 [3]. Can anything be done to address this, especially for node, where the compile time cost of a super optimizing compiler might be beneficial in certain applications?

[1]: https://bnjbvr.github.io/perf-wasm-calls/

[2]: https://hacks.mozilla.org/2018/10/calls-between-javascript-a...

[3]: http://speed.wasmer.io/comparison/

Re: Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code

#127
post #98

Earlier quoted context omitted.

sure, you can compile an application, but if you want to target everyone, you have to do it on at least 3 architectures (linux, mac, windows) and as a user, i am either lucky if my architecture is supported, or i am scrambling to find an alternative. in my case i actually have all three. so when i see a new application i want to try, i check which one is best supported and then pick that. several apps run only on win…

> sure, you can compile an application, but if you want to target everyone, you have to do it on at least 3 architectures (linux, mac, windows) Is that really a big deal, though? From what I understand (and I could be wrong, so correct me if I am), most of the headaches involved in multi-platform development is the OS specific UI. Video games, for example, don't find porting to multiple architectures all that challen…

at this point it is mostly a problem of perception, and apparent complexity.

portability is not the problem, but you still need to learn how to package for each different system, you have to maintain at least 3 sets of build-to-package instructions and understand each ecosystem.

for example, i only develop on linux. yet, packaging for all linux distributions is still a hurdle. why can't i just compile and upload to my website?

i have never packaged for windows or mac, and the thought having to learn those alone makes me turn away in disgust. i am probably wrong, and packaging for both is way easier than i think. but that's exactly the point of the problem being based on perception and apparent complexity.

in order to package for all three systems, i need to first of all want to do that. and i find that i don't care enough to want it.

Re: Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code

#128
post #123

Earlier quoted context omitted.

Literally everything you said except the part about using the language you want has been true of Java for at least a decade. Everything old is new again.

Java... Are you kidding. The UI stack and distribution model is horrible compared to WebAssembly. The resources available for HTML/CSS cannot be compared with JavaFX, Swing or whatever the other original stack was. And the Applets sandboxing was obviously so horrible everyone killed it. WA is amazing here copying the existing and already hardened JavaScript model.

But in that case we already have all that with Electron. Unless you want to program in C/C++ or Rust, compiling your language to JS would probably result in an image that's both smaller (because you won't need to bring your own GC) and faster (because you'll be enjoying JS's JIT) than WASM.

JS is a better compilation target (you don't have to use JS directly) than WASM for the vast majority of languages. WASM is great for when you have a bit of code you'd like to write in C and use as a library from JS (or a language compiled to JS).

Re: Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code

#129

Earlier quoted context omitted.

"Certainly many developers are comfortable writing things in python," But python is a high level script language with gc. WebAssembly is very lowlevel, so the people who could and would write in python will not write in wasm and also not in C. Wasm is still awesome, it is just not, what many hope it will be. And a distribution format for drivers? Well, I am not a low level expert, but that seems very unlikely to work…

The point is that people are clearly willing to leave magnitudes of performance on the table just so that they can use their language of choice. That's what Webassembly enables today: You can use C/C++, Rust, Go and several others. Of course the ecosystem is not as mature. Languages with a big runtimes aren't good candidates for lean web apps. Performance isn't the dealbreaker though.

"people are clearly willing to leave magnitudes of performance on the table just so that they can use their language of choice"

Certainly. It also makes sense, as programmers time is usually worth much more than computing time.

Re: Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code

#130
post #128
post #123

Earlier quoted context omitted.

Java... Are you kidding. The UI stack and distribution model is horrible compared to WebAssembly. The resources available for HTML/CSS cannot be compared with JavaFX, Swing or whatever the other original stack was. And the Applets sandboxing was obviously so horrible everyone killed it. WA is amazing here copying the existing and already hardened JavaScript model.

But in that case we already have all that with Electron. Unless you want to program in C/C++ or Rust, compiling your language to JS would probably result in an image that's both smaller (because you won't need to bring your own GC) and faster (because you'll be enjoying JS's JIT) than WASM. JS is a better compilation target (you don't have to use JS directly) than WASM for the vast majority of languages. WASM is grea…

Yeah valid point. I am quite comfortable with HTML but only tolerate JS with heavy use of TypeScript. For me C# and Blazor sound quite cool. The size is my biggest concern as well.
Post reply on HN