12 ms·
Why WebAssembly Is Faster Than Asm.js
- 6nf 10y agoWhat languages do you all recommend for compiling to Wasm? I know Rust is an option and something like Nim would probably work well. What is the future of Wasm?
- overgard 10y agoHonestly I'd only use C and C++ with this. It's not going to be a good target for anything that currently requires a VM (most garbage collected languages)
- astrodust 10y agoWhy not? Once someone implements a good-enough garbage collector that can be used by a multitude of garbage collected languages.
- coltonv 10y agoDifferent langauges demand different features in the implementation of a garbage collector. A garbage collector that every language implementation could use would basically be a set of functions that languages could use to implement their garbage collectors, but at that point the library would be tiny and the per-langauge implementation of garbage control would be huge.
- astrodust 10y agoI'm not sure that the garbage collector in Ruby, Python, Node.js or Perl is going to be radically different. They all have their own implementations for historical reasons, not because they have such wildly different concerns. Java has a strange way of handling object lifetimes that complcates things, but it's not the norm.
- coltonv 10y agoWell you can't even compile Ruby, Python, Node, or Perl to WASM, since you can't compile dynamic scripting languages to LLVM. You could, for example, interpret Python by compiling the CPython interpreter to WASM (though that would mean an absurd bundle size), but this doesn't solve your problem since the python garbage collector is in the CPython source and you can't just remove it nor can you use a different langauges garbage collection because every language represents objects differently.
- astrodust 10y ago> you can't compile dynamic scripting languages to LLVM... Considering Rubinius uses LLVM that's not quite true, and further, just because people haven't succeeded in taking it all the way it doesn't mean you can't. Maybe it's just hard. For example, if you're willing to sacrifice a few features that make compilation difficult you actually can compile Ruby: RubyMotion (http://www.rubymotion.com/tour/how-it-works/ http://www.rubymotion.com/tour/how-it-works/) does it. The biggest problem is something like eval, but if you're willing to live without dynamic features like that you don't have a lot of impediments to compiling to LLVM.
- ed_balls 10y agoHow come? I thought WebAssembly was designed with GC in mind.
- icefox 10y agoRust doesn't require a garbage collector
- kibwen 10y agoOr a VM, or (in the extreme) even a memory allocator (which is how it gets by on microcontrollers).
- prewett 10y agoUnless I'm missing something, I think most languages will be fine. I'd think pretty much every language will need to cross-compile their runtime library to WASM, which would include their garbage collection. C/C++ will obviously be easiest to map onto WASM, but I'm guessing other languages won't be too far behind. LLVM already has a WASM target.
- nv-vn 10y agoMost garbage collected languages don't require a VM as far as I'm aware. D, Go, Lisp, Scheme, Haskell, ML, Nim, ...
- dawidloubser 10y agoWASM is going to make Rust [1] shine like nothing before. I love that all the Mozilla articles keep mentioning it together with C/C++. Unfortunately, writing Rust is an order of magnitude more difficult thatn writing ECMAScript, so hopefully it doesn't create a negative response from hordes of ES developers that want to check out this WASM thing. But it's so much more suited than C/C++ (the other obvious candidates). In a nutshell, WASM is not really intended for higher-level languages with garbage collectors, etc. For that kind of work, I'd stick with ECMAScript. [1] : https://www.rust-lang.org/ https://www.rust-lang.org/
- steveklabnik 10y agoThere's been a reasonable amount of success for JS programmers moving to Rust; npm is now using it for backend services, for example. There is a big semantic gap, but many don't find that insurmountable.
- ChicagoDave 10y agoA colleague, Thilo Planz, is working on an Interactive Fiction VM based on the Glulx specification (1) called glulx-wasm (2). If completed, this will be integrated with fyrevm-web, a web platform for glulx+channel IO stories. (1) http://www.eblong.com/zarf/glulx/ http://www.eblong.com/zarf/glulx/ (2) https://github.com/thiloplanz/glulx-wasm/ https://github.com/thiloplanz/glulx-wasm/
- msoad 10y agoWithout a GC WASM is very hard to use for regular web development tasks. When GC infrastructure lands lots of mind-blowing stuff will happen. Things like JVM and .NET running in WASM. A lot of web people don't realize magnitude of impact WASM will have on the web.
- Touche 10y agoWhat's the benefit of JVM in wasm over compiling JVM langs to js?
- dawidloubser 10y agoI think you're missing the core use-case of WASM. It's not for general app development, which will stay with JS. It's meant to provide plug-able, high-performance functions for heavy computational tasks - crypto, game rendering, heavy in-browser data analysis, etc etc. I double JVM in WASM makes sense at all - though somebody will probably do it in anyway. WASM is not meant to be good at Garbage Collection, etc. It's not a design goal at all.
- Touche 10y agoWhat's the benefit of JVM in wasm over compiling JVM langs to js?
- jagger27 10y agoThe web and desktop computing.
- hackcasual 10y agoI would think of WASM the same way you'd think about JNI. It provides a way to have processor intensive integrate with a broader system.
- paulddraper 10y agoIsn't that JS?
- muizelaar 10y agoTo get good performance on running JVM or .NET WASM will probably need more than just GC support. JVM/.NET JITs rely on inline-caches that aren't currently expressible in WASM. There are ideas about ways to make this work, but it will be a while. The other thing preventing the use of JVM or .NET is that porting the runtimes over isn't easy. i.e. You can already run this bytecode in a browser but it isn't widely used. (http://jsil.org/ http://jsil.org/, https://github.com/decatur/j2js-compiler https://github.com/decatur/j2js-compiler, https://github.com/plasma-umass/doppio https://github.com/plasma-umass/doppio, https://github.com/mozilla/pluotsorbet https://github.com/mozilla/pluotsorbet etc)
- genjipress 10y agoWhat seems most important about WebAssembly is that it is essentially a universal language runtime. It's not that what it brings to the web is unimportant, just that it seems like we're also getting a way to do truly cross-platform language deployment as a bonus. Am I wrong about this?
- randiantech 10y agoWell, Java bytecode already does that. The cool thing about WebAssembly is that runs (or will run) on any browser.
- kuschku 10y agoMaybe they should have just used Java bytecode as WASM format? Then we’d have an entire existing ecosystem available.
- futurix 10y agoNot with Oracle being litigious pricks.
- dawidloubser 10y agoHear hear! Java was on a great trajectory before being stagnated by corporations and politics. Such a pity, because now we have to re-invent it. The silver lining, is that many things usually get better the second time around. Let's see what WASM hold - it's pretty limited in its current form.
- kuschku 10y ago*The third time around FTFY. The second time around is usually so troubled by politics that there's an entire Wikipedia page about the topic of the second-version syndrome. And WebASM is in every way inferior to Java still.
- deleted 10y ago
- hackcasual 10y agoUsing Emscripten (with embind) 1.37.3 it takes slightly over 1 second to initialize a 2.7mb wasm file. The JS version shows slightly under 300ms for parse time, obviously not the same as the full WASM pass, but it does significantly delay initial page load. The positive side is what took 250ms to run with cold JS (nothing JIT compiled) and 35ms after a few runs takes just 5ms the first time in WASM. This is on Chrome Canary on Windows. Is there anything I'm missing to speed this up?
- jsheard 10y agoHave you tried compiling your project with the -Os flag instead of -O2 or -O3, so the optimizer prefers to generate smaller code? Performance will be slightly worse but a smaller wasm binary means less for the browser to deal with on initialization.
- hackcasual 10y agoYes, it's compiled in Oz.
- azakai 10y agoStartup time is a known issue specifically on Chrome. It's being focused on, so improvements are expected.
- hackcasual 10y agoGreat, I'll run the benchmark on Firefox. Really excited for this.
- azakai 10y agoCool. And if you see slowness on more than one browser, please file a bug, it could be something in the toolchain we need to fix (if it's fast in one browser but slow in another, the slow one probably just needs to improve).
- 10y ago
- wtbob 10y ago> indexes are LEB128s It's just a personal nit and beside the point of the (rather short) article, but I've long felt it sad that the more correct 'indices' is so rare and the correct-but-inelegant 'indexes' is so very common.
- nitemice 10y agoSo let me get this straight: WASM is basically asm.js, but without having to go through javascript? The future has changed! https://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript https://www.destroyallsoftware.com/talks/the-birth-and-death...
- adamnemecek 10y agoI know it's easy to dismiss it but wasm will be th e biggest deal in the world.
- Zikes 10y agoThere are already talks about compiling Go to wasm: https://github.com/golang/go/issues/18892 https://github.com/golang/go/issues/18892
- stymaar 10y agoI'm not sure I see any interest in that tbh: what's the point of porting a memory-safe (with GC and runtime) on a VM especially dedicated to remove the costly memory safety part of JavaScript. Plus, the concurrent model of Go doesn't really shine if you run it in a single threaded configuration (which is most likely to be the case in wasm). I might be missing something but to me it sounds like pure hype to put go and wasm together.
- themihai 10y ago>> I'm not sure I see any interest in that tbh: Running other languages(than JS) in the browser is interesting for sure.
- bradfitz 10y agoYou're confusing concurrency and parallelism. Even with GOMAXPROCS=1 (1 CPU running Go code), it's very liberating to be able to write blocking Go code and not worry about callbacks or async/await and let Go's runtime deal with it all while you write concurrent code.
- gcr 10y agoWhy aren't we standardizing on something like Java bytecode or LLVM IR or CLR? What problems with those existing technologies could wasm solve better?
- darpa_escapee 10y agoMy friend, where have you been for the last 5 years? Web developers have been reinventing the wheel every 3-6 months and calling it innovation.
- Rusky 10y agoA fair criticism of a lot of web tech, but not of WebAssembly, which is doing many things JVM/CLR/Flash/etc. never did.
- throwawaysbdi 10y agoAnd what are those exactly? JVM and CLR bytecode is totally platform agnostic and both support many languages without trouble. Apparently they aren't cool anymore so we need to spend another few thousand man years building another system in their image
- Rusky 10y agoBut they don't support the primary reason for asm.js and thus wasm- C and C++. They also, as you note in another comment, do not have the appropriate security model for web apps.
- pjmlp 10y agoI guess you never did any .NET development. .NET 1.x introduced Managed C++. .NET 2.0 replaced Managed C++ with C++/CLI due to feedback from C++ devs, regarding keywords and how GC types were declared. C++/CLI was submitted to ANSI C++ as standard proposal. UWP introduced C++/CX, although it does compile to native code and interoperates with .NET Native instead. Or Flash for that matter, which had a C++ compiler called FlasCC.
- ballenf 10y agoThe most popular language that you can't compile into wasm is Javascript? This issue was closed 12 hours ago: https://github.com/WebAssembly/design/issues/219 https://github.com/WebAssembly/design/issues/219 I know it's cliche and been written about ad nauseum, but this really does feel like the trojan horse threat to MS, Apple and Android.
- dualogy 10y agoWhat exactly is the "threat" to those players here, wasm? It baffles me when people are asking for "a mechanism (aka hidden behind-the-scenes magic) for objects and GC" in an assembly language =)
- Rusky 10y agoIt makes complete sense to ask for GC support. Even if it's never used to implement GC-d languages targeting WebAssembly, it's still important for integration with the Javascript GC. (I imagine the threat here is that the more things can be deployed as web apps, the less they depend on any particular desktop OS.)
- runeks 10y agoWhy not write the GC in WebAssembly?
- readittwice 10y agoHow would you implement determining the root set? So how would you detect which local variables reference an object? The Gc needs to keep these objects alive. AFAIK even conservative root-scanning is not possible right now. Please correct me if I am wrong: With the current bytecodes it is only possible to access the heap but not the stack. To make things worse, object references could also be in registers.
- Rusky 10y agoTwo reasons, beyond the sibling comment's notes that it's currently impossible: 1) You can't integrate it with the Javascript GC for interacting with the DOM and other JS-side objects 2) Now you have to distribute the GC with every app that uses it
- kevin2r 10y agoBy the time wasm supports GC languages like python or ruby, javascript may get a lot better. Will people still want to write client side apps in python?, even if it means that it will run slower and also you have to download the language runtime on a webpage load.
- cm2187 10y agoJS is not to everyone's taste. And certainly not to mine. In the line of business world, there would be a huge value added being able to use the browser as a distribution mechanism for what are effectively desktop apps, developped in a high level but statically typed language like VB, C# or Java. I don't think downloading the app everytime is a big deal on an intranet/local wifi. Also with things like the core CLR, the assemblies should be smaller.
- grey-area 10y ago{} + []
- tambourine_man 10y agoI though SIMD had already landed on WebAssembly. That will make asm.js look a lot slower and should get it closer to C/C++ where it's still lagging.
- markdog12 10y agoNot yet: http://webassembly.org/docs/future-features/ http://webassembly.org/docs/future-features/
- frik 10y agoWho else thinks that Asm.js was okay, but WebAssembly is evil and might destroy the current web landscape. It's like a trojan horse. Guess which companies are involved.
- eridius 10y agoWhat makes you say this?
- tannhaeuser 10y agoWASM will be used to ship browser-in-browser runtimes (WebKit+FreeType already compiles to WASM) to make ad and tracking blockers impossible.
- TomMarius 10y agoWhat's stopping you from not using such sites?
- tannhaeuser 10y agoIt's just that I find the WebAss propaganda dishonest and the discussion here naive. I personally have no problem discussing the economies of publishing, and I'm also not against ads. Tracking, OTOH, needs to go away.
- TomMarius 10y agoI don't see any propaganda, I see a very interesting, beneficial and good technology. What's naive about that? No one says it has no downsides; but some people don't consider it a downside. And again - if you don't like being tracked, there's nothing easier than not visiting these sites, because that's simply the price of visiting the page. Obfuscated JavaScript code is about as hard to read as equivalent WebAssembly code, maybe even harder, so you still have exactly the same options to find out you're being tracked.
- cm2187 10y agoDo we know if we are likely to see support for WebAssembly for all platforms? It looks like a way to bypass the app store. I am surprised apple or google (on android) would be happy to do so.
- tannhaeuser 10y agoExactly. Apple won't support WebAss, and I'm WITH them on this one. Why does a browser have to run native apps with a laughable/non-existant, designed-by-comitee API? That's what the operating system is for IMO. WebAss is a technical solution to an economic problem: lackluster SW sales and adblocking
- cm2187 10y agoI don't agree with you. The only language that allows truly cross platform development right now is javascript. It's a language I do not like and I believe I am not the only one. In fact the popularity of extensions like typescript is an evidence of the challenges of using what was meant to be a simple scripting language as a full blown programming language. WASM, if it allows to run high level languages like c#/vb/python/java, will enable a huge developer base to start writing truly cross platform, productive apps with a single code base. So it would be a solution to a fundamental technical problem: the fragmentation and incompatibility of proprietary platforms. As a side, it would have another benefit (which would make it even less palatable to Apple but should motivate Microsoft to develop a CLR for WASM): as the apps would be cross platform, it would lower the barrier to entry for alternative mobile platforms. If the same app compiled to WASM runs on every platform, a Windows mobile OS (or any other challenger) would immediately have access to the same apps that are available for iOS or Android.
- tannhaeuser 10y agoThe end user won't benefit from the portability aspect, though. He/she has to load the damn app anew on every device and every session. I'm not against portable bytecodes (though I find it pointless, and proven to have failed in the past); it's the mating to the Web that I'm concerned with, and the infinite potential for tracking and other privacy invasion. To bring portability in a meaningful way, Apple and Google have to agree on a common API for touch, phoning, GPS, USB, power management, proximity, NFC, UI. Not going to happen. So why bring yet another avenue for tracking and malware to browsers? To top it, lets base it on C and SIMD primitives. Lets ditch HTML and draw to a canvas all the time, accesibility, hyperlinking, etc. be damned. Because we don't like JavaScript.
- thedonkeycometh 10y agoIs this like Flash?
- inDigiNeous 10y agoIs it possible to compile javascript to WebAssembly or asm.js?
- orthecreedence 10y agoBelieve it or not, most browsers already run javascript ;)
- inDigiNeous 10y agoThanks for pointing out the obvious. That's not what I asked, I asked whether can you compile javascript to WebAssembly, without having to parse javascript source files on the fly and expose source code to the javascript engine, but instead provide just the WebAssembly output directly.
- Mindless2112 10y ago> indexes are LEB128s This article is promoting how fast WebAssembly is to parse (and no doubt it is faster than JS), and yet LEB128 is a slower-to-parse representation than "prefix varint" with the same cost in bits [1][2]. It seems the designers didn't actually care what was faster. [3] [1] https://news.ycombinator.com/item?id=11263378 https://news.ycombinator.com/item?id=11263378 [2] https://github.com/stoklund/varint https://github.com/stoklund/varint [3] https://github.com/WebAssembly/design/issues/601 https://github.com/WebAssembly/design/issues/601
- Ajedi32 10y ago> Implementors have discussed and concluded that while alternative encodings might offer improved size, the intention to support layer 1 (allowing outer wrapping format specific compression), and the degree to which LEBs are well known, outweighs this advantage for MVP. Interesting. Any idea what's meant by "layer 1" here?
- Ericson2314 10y agoI predicted this before, but somebody will do a cloud with webassembly. With all the extensions, this becomes quite an interesting middle ground between VMs and containers.
- infogulch 10y agoWhat if the javascript interpreter / jitter was built in WASM and the jit target was WASM? The browser could reduce its' surface area to just network, html/css layout, compositing, and wasm. Js just becomes a special case with an automatically loaded wasm plugin.
- erikpukinskis 10y agoWASM has it's uses, for games and such. But on the web, the more weird stuff you do, the more friction you tend to introduce to your users. You can boot a JavaScript app, but the startup time will push people away. You can take months to replicate iOS animations, but the lack of bookmarkability will hamper your virality. Now you can compile C++ and run it in the browser, but you can't use any of the existing web frameworks, and browser support is hit or miss. The real questions are: what are you really doing that actually couldn't be done with Craigslist-level technology? Does your application need to look and feel the way it does because you want show off what you are capable of, or because your customers would actually like you less if you did less? What people keep missing is that the Web isn't a platform, it's an idea: It's the idea that the lowest common denominator, or whatever crappy text-based document format is supported in every single device ever made, is actually good enough for almost everything. And you can add fanciness, and you can add features, but the weight of the web pulls all content towards that lowest common denominator. This drives iOS developers crazy, because they want to be special snowflakes who make animations that run at 100hz and might make Dieter Rams notice them in the lunchroom. Platform after platform keeps challenging the web, and the web keeps chugging along. Because the web is not a tool, it's the idea that we should communicate with as many people as we can, and to do that we should use the simplest technology that will do the job.