434 points · by galaxyLogic · 6y ago · 242 comments
Ten years ago browsers were capable to do pretty much the same but with Java on board that they all had at those times.
WebAssembly is conceptually close to JavaVM (JITed bytecodes) but due to its architecture Java allowed as a) reflection (JS to Java calls) as b) exposure of DOM model into Java execution space - DOM API even now is defined in terms of Java interfaces by the way.
WebAssembly is a step in right direction but the evolution looks as Waltz - two steps forward two steps back with the twist.
Now we are able to run ray tracers compiled to WA on browser side but we've lost an option to apply the results to DOM elements directly.
To say in CSS:
my-component {
behavior: my-native-event-handler url(controllers/my-controller.class);
flow: my-native-layout-manager;
}WA is much smaller, assumes way less, is isolated from DOM and JS code way better, communicates with them via message-passing. It has a smaller attack surface, and less room to screw up in the implementation.
Yes, I think not having WA married to DOM is a good idea from many angles. One of them is security, of course. Another is wider applicability: a WA VM could be useful outside the browser, and it already is.
I was using asm.js in the past, but WASM gives a noticeable and necessary performance boost.
Which specific CPUs or applications that you emulate really take advantage of the performance boost that WASM provides?
Right now the emulators are all in JavaScript (except for MAME) which makes integrating with the IDE's debugging tools a little easier. It's performant enough for now, since we only have 8-bit platforms at low clock speeds.
Integrating a C emulation library like https://github.com/floooh/chips should be doable, since it doesn't have any dependencies.
[1] https://tech.ebayinc.com/engineering/webassembly-at-ebay-a-r...
Edit: here's the PR for switching from asm.js to WASM, in case anyone's interested: https://github.com/vector-im/riot-web/pull/7385/files apparently it merged in Oct 2018.
I'm excited to see how I can improve upon it in the future, and make it even faster! It's on GitHub here, any feature requests or suggested improvements would be greatly appreciated too: https://github.com/silvia-odwyer/photon
The browser support is good enough for our customer base, as it works across all operating systems and mobile devices, and we can fall back for asm.js for IE11.
Using the whole .NET ecosystem from browser, yea I think there's some good success stories ;)
PSPDFKit uses it for their pdf editor.
Unreal Engine/Unity uses it for their browser support.
It's used in production in many places either as modules or entire apps.
Except for some noob mistakes when implementing the PoC it’s worked remarkably well, much better than I though it would.
Pretty sure Electron provides IndexedDB though.
(Ref: https://nolanlawson.com/2015/09/29/indexeddb-websql-localsto..., vaguely https://nolanlawson.github.io/offlinefirst-2016-03/)
The only downside so far is that the embedded size is quite large, so we do take a small hit in startup latency (sub second still) and if we ever end up having a requirement to work across the internet (I doubt it) it’s going to hurt because we’d be looking at a 3mb+ download (quite cacheable though.)
Anyway, point is our need was mainly SQL the language and not so much the storage, that’s kind of secondary, though SQLite really makes that part easy too.
You can jump to 47 minutes in to catch a little bit of the web animation in action, but as it was over conference WiFi, it was a bit wonky.
In my experience in SF I encounter many never-JSers. Being a JS fan, for certain things, I don't get the hate. So maybe I feel threatened in a way, but I'm not going around wishing for the death of python or Haskell. That's all. I am reading random internet commenters and getting slightly upset. That's on me.
I can't imagine JS will go anywhere anytime soon, especially since it still needs to be called from DOM manipulation,but the ability to code a full stack in a single non-JS language and run it at near-native performance is going to be very useful as more apps become web based and complex. Even from a skills point of view, you can now have backend and front-end developers skillsets are slightly more merged so easier to swap around resources.
Think about how you would do ML with just python. That’d be insane. And thankfully the packages you need are implemented in c or cuda with python bindings. 99% of ml people never see the insides of np, sklearn or tf. But you’re glad these aren’t implemented in python.
Similarly, you’re glad for webgl if you need to do lots of parallelizable computations (cfd, ml, 3d). But glsl was never bashing at js. Just that using js for these task isnt feasible.
Similarly, now you can use fast code from js. Essentially, you have a bunch of matrices use webgl, otherwise wasm. And orchestrate everything from js. Like ml peeps do with python, c and cuda.
For the better or the worse...
https://www.forcepoint.com/blog/x-labs/browser-mining-coinhi...
Could someone in the know shed some light in this matter?
Specifically, it is done within the WebAssembly Community Group (open to all), then shuffled through the WebAssembly Working Group (open to paying member companies only) for advancement through the official W3C processes. This is a reasonable process hack for getting openness within the W3C structure.
That said, the "Recommendation" stamp of approval is indeed being overblown in this article. What it practically means is:
- (Pro) now all of the member companies of the WebAssembly working group (https://www.w3.org/2000/09/dbwg/details?group=101196&order=o...) have pledged not to use their patents to sue anyone who implements the WebAssembly specification.
- (Con) now there is a static "dead standard" at some https://w3.org/TR/ URL which people will treat as more official than the actual living drafts at https://webassembly.github.io/spec/, despite the living drafts being actually up to date with implementations and the dead standard existing only for patent purposes.
--- quote ---
Developer reference documentation for Wasm can be found on MDN's WebAssembly pages. The open standards for WebAssembly are developed in a W3C Community Group (that includes representatives from all major browsers) as well as a W3C Working Group.
--- end quote ---
> Paragraph 1
>
> Paragraph 2
Whereas you'd get two sequential quote blocks by using an unquoted empty line: > Quote 1
> Quote 2The way that coding language and deployment/executable language have been tied together (JS for both) has served as a force that pushed everyone toward that single language.
Now that WebAssembly promises to remove that force, will it be a free-for-all, or will other forces push toward standardization on a few languages? And if so, what will those forces be?
To be even more specific, in the early days now, the main allure of wasm is performance. So the focus will be on languages and toolchains capable of generating optimized native code. Out of those, look at which ones are easy for the developer to set up (both in general, and for wasm) on all popular developer OSes.
So, I'd say that Rust will probably be the biggest beneficiary.
I imagine binary size would be a concern for web development, what is a negative for complex runtimes... But then, if I carefully set the compiler to trim dead code, my Haskell email server is smaller than any modern JS framework (still larger than a new version Jquery), so the runtime may not actually make much of a difference.
The drawback of JavaScript has so far been its low execution speed, maybe WASM will make it run faster.
In other words maybe WASM will not be the downfall of JavaScript but its uplift.
In short, I suspect the actual instructions executed when JS runs on a modern interpreter are already pretty damn close to what a fairly well-optimized JS-to-WASM compiler would provide. If you want more major gains I think you'd have to start looking at locking down (or at least providing the option to lock down, in performance-critical code) the ability of Javascript to do all kinds of wacky stuff at runtime.
I recall one of the spec authors saying in an HN thread that a GC would be added eventually, back in the infancy of WA. I'm not sure if that's still on the cards or if there have been any updates on the subject.
DOM access will be possible through the interface-types extension [0], but no host supports it yet AFAIK. Also still a very tricky problem.
LLVM has an interface for GCs such that the host language can provide LLVM with information about what kind of code to generate at the boundary between the application and the GC, but that’s just shim code; not a full GC implementation, and even then I’m not sure of any languages that make use of it.
Even still, it’s cool to see the WASM folks trying to tackle these big tricky problems!
It's enticing to imagine being able to open a wasm file and seeing an application on the page. Kinda like how you can just open an image or a video in the browser, without rendering it via an html document.
Of course, why not just use a small HTML+JS shim for your WASM?
I don't think changing this is even desirable. It's much easier and cleaner to standardize a stdlib of accessors.
This wasn't the intention when the script tag was introduced. It's interesting that the web standardized on one programming language.
In hindsight I feel like this isn't surprising. How many platforms (that aren't themselves operating systems) support scripting in more than one language? Vim/Neovim is the only one I can think of off the top of my head.
AFAIK, the reason the DOM and JS GC are very coupled is because there can be loops between the DOM and JavaScript: the DOM can hold JavaScript resources, which themselves can hold DOM resources. As long as these loops are avoided (by not allowing the DOM to hold resources within the WASM heap), this is not an issue.
There are many things to be done in the standard, in the implementations, in the frameworks...
[0] https://www.destroyallsoftware.com/talks/the-birth-and-death...
That's just a way of saying that "the best way to predict the future is to invent it" (and do so before people who were "predicting" it).
If you knew about asm.js and Google's (now abandoned) Nacl and PNacl, there's nothing surprising about the development of wasm. It's been 10+ years in the making.
And 20+ years ago Microsoft's browser had ActiveX plugins (which didn't use a VM and were really unsafe and unportable). Making a portable, sandboxed bytecode solves an obvious problem with that.
Also the JVM ran in the browser, etc.
The talk isn't trying to sell itself as 100% original. It makes reference to asm.js and a game demo that already existed at the time of the talk as well as repl.it.
Despite that, I do think it makes a unique insight that even though JavaScript is ubiquitous, it will NOT be the language that future languages compile to, but rather a bytecode perhaps inspired by JavaScript that will be the language of the future. Also, importantly this bytecode will win; that is most languages will the ability to directly compile to or have a VM in this bytecode.
Moreover this bytecode has the potential to entirely supplant native code and can do so with equal or better performance.
At least to me, neither of those were obvious insights even though I knew of these plugins and JSLinux.
First off, those plugins died. Silverlight, ActiveX, Java on the web, Flash, all of these died out and were replaced by JavaScript before wasm really took off. It might've looked like the end state would be a version of JavaScript "winning."
Second, things like PNacl, Emscripten, etc. still seemed like curiosities (as the talk refers to when showing Repl.it). It wasn't clear that they or the ideas they championed would get widespread adoption.
These days it is looking more and more likely that wasm is going to become a target for all sorts of different compilers. The fact that it's a major compilation target of Rust, a language that's about as far away from what I would've thought of as a language for the web as possible, is striking.
And though we're still a long ways away from running everything on WebAssembly, it no longer seems as exotic an idea as it once did to me.
And because of that, as well as the fantastic presentation, I still return to this talk every so often awed at how much closer we are to realizing Metal.
There's still a lot of room for the talk to go very wrong, but it's not as far-fetched as when I first watched it.
EDIT: Put another way; the talk is interesting to me because it emphasizes the birth and death of JavaScript. It talks about a world where the same forces that propelled JavaScript to towering heights of popularity ultimately cast it aside and create a world not possible without JavaScript, but in which JavaScript itself essentially no longer exists.
I interpreted that part of the talk as hyperbole and sarcasm. It was saying that programmers will be so far removed from how computers work that they'll happily program against a model that has five layers of abstraction that simply serve to provide the original interface of the bottom layer.
Bytecode, by its nature, has to be translated into native code -- the way for it to be 'faster' than native code is to be native code. In software, you can do this with static or JIT compilation. The hardware people do this by changing their CPUs to make the things that people do in the bytecode faster. (Apple introduced new floating point CPU instructions in their iPhones just to make JavaScript faster.)
Originally my conception of the video was more like this commenter below: It’s been a while since I’ve watched the video but its more about JavaScript becoming the universal assembly language.
I guess a lot of people are saying "he predicted this" without referring what specifically he is predicting.
FWIW it's not clear to me that WASM is going to do that. Everything I've heard from the team says that WASM and JS are complementary. Not that WASM will cause JavaScript to die.
I think there's some possibility of that happening in the distant future, but it's far from obvious. I think JS VMs will always be better at running JS than WASM VMs running JS engines, and all the JS out there will exist for a long time.
Also, JS is at a pretty good level of abstraction to manipulate the DOM, whereas C, C++ and Rust aren't. And it has some good syntactic shortcuts. Despite being a Python person, I would probably even argue that JS is better to manipulate the DOM, despite JS and Python being very similar otherwise. Function literals might be one reason.
So when people say "he predicted this", it would be nice to be specific about what the prediction was. WASM is a step in that direction but I would argue it's also fairly clear given that asm.js existed and he showed it. The real question is if WASM can handle all these use cases. Working on a language has made me appreciate many reasons that it's hard to make a polyglot VM. Tiny changes can bias your VM towards one compilation source vs. another.
You are technically correct, but at the same time I do think this way of framing it is selling Gary Bernhardt a little bit short. There is still an uncanny part in knowing all the right things at the right time to predict the future.
I guess it's just as accurate when Gary Bernhardt says it as when everyone else says it. It's not exactly a theme that's gone overlooked before. But still... executing bytecode in the browser goes way, way, way, way back.
EDIT: some quick googling shows it's already being done
https://hacks.mozilla.org/2019/03/standardizing-wasi-a-webas...
Check out Wasmer! https://wasmer.io/ : along with other runtimes we are enabling the use case of WebAssembly programs as standalone applications that can run in any platform, or as libraries to be usable in any programming languages (disclaimer: I work at Wasmer!)
If you want to provide a plugin or extension interface, and want to give those plugins a limited interface rather than making them all-powerful, embedding a WebAssembly runtime gives you all of that plus the ability for people to easily write plugins in any language.
Also see https://hacks.mozilla.org/2019/08/webassembly-interface-type... for an illustrated description of how that'll work smoothly across languages.
No, you would still have to provide an application programming interface for every target language you want to support.
1. https://blog.cloudflare.com/webassembly-on-cloudflare-worker...
2. https://www.fastly.com/blog/announcing-lucet-fastly-native-w...
EDIT: here it is: https://medium.com/wasmer/running-webassembly-on-the-kernel-...
syntax? subjective, and it would also mean all C-likes belong in the dustbin.
performance? Why would python, as a language, be significantly more performant? It's just as dynamic.
ecosystem? JS community is huge, JS package managers are huge (even though not flawless, but nothing their python counterparts do better)
I mean I can surely imagine there's better alternatives for JS, as a language. But python...?
For me, personally, it's a lot of effort to switch between languages. So when I'm building a web project and most of it is django/flask/python/etc, but I want something more dynamic than a HTML form post/browser reload... I need to do it in Javascript. Not that I can't javascript, I can, it's just hard to change over and I'm slow to write it. It would be a whole bunch nicer if I could just stay in the python mindset for those small pieces of code.
Do I think python is "better" for the web? No. do I think it's faster? Doubt it.
Do I think it's "better" for my use cases? Yes - And that's the power of WASM. It allows people to do what works for them.
- New ECMA standard every year VS. new PEPs every year
- Modules and classes: cyclic dependency hell, obscure multi-import issues, __init__.py ugliness, imperative class declaration. Python only figured these things out much earlier to the extent that it has actually figured these things out.
...
You expect that to carry over to WASM environments?
Also comparing languages based on syntax and ecosystem is not very clever idea.
In my particular case, I've been learning Python for Data Analysis for about one year, and a few months of Haskell (love Haskell so far, but my interest/job is related to data analysis and web dev). I've heard bad things about Python as first programming lang (weakly typed and bad OOP implementation).
Personally I'd also avoid anything with a fatter runtime than maybe Go or C#. If it doesn't already, I'd expect C# and .net generally to have really good WASM support, actually. And even those, unless it becomes standard to ship their runtimes with a browser, you're talking about a pretty fat package to ship before the program can even start running.
Most interpreted languages (like Python) running on WASM will probably be notably slower than Javascript running outside WASM, for the reason that they'll have similar limitations on optimizability, will have had fewer person-years put into optimization than Javascript (which has seen tons of investment from e.g. Google), and will be running on an interpreter in the WASM VM rather than a C++ (or whatever) native interpreter. And they'll have the problem of needing to ship an interpreter, similar to the runtime problems for the languages above.
For the best experience you want something fast-loading and well-performing. That means small package size and not too deeply nested in terms of abstraction on top of WASM. If you want a better experience on both fronts than JS, which has the benefit of already having its interpreter bundled with the browser and running on a native, highly optimized interpreter—IOW if you want running on WASM to actually be a win in any meaningful UX way—you'll need to look at fairly low-level languages, I think. C++ is a good bet—people are quick to shit on it, but it remains hugely important in GUI application development—or, if you're wanting something hipper, Rust, perhaps. Go or .net-family languages might be OK, future-proof-ish choices if you don't mind sacrificing load time a bit. Toss Swift in that bucket too, I guess.
The one I've been looking to the most is Rust, as it compiles to a smaller size, doesn't have a GC to ship (by default), and is not C/C++. C/C++ seem to be the other common WASM languages.
Edit: Just saw you're a beginner programmer, I probably would not suggest Rust as a first language. Web Assembly in general may not be a good starting point, but if you're set C++ might be slightly better. (I tend to suggest Python as a starting language)
Also as someone who uses Python regularly, Python is by no means a perfect language. I am assuming you only know Python since it's an attitude I often come across for devs who only develop in Python and believe it's the superior to every language in every way.
https://hacks.mozilla.org/2019/04/pyodide-bringing-the-scien...
I think it's really great but it would be better to have company from all around the world
I'm curious too - was there really no non-Chinese company that would endorse this?
W3C members are visible here: https://www.w3.org/Consortium/Member/List
Those are the members that decided that WebAssembly is now an official web standard, not the testimonials.
I'm investigating more about the voting system here, https://www.w3.org/Consortium/Process/ERB.html.
I think it's just a little shocking as it kind of makes it seem like nobody outside of China supports WebAssembly.
I think having a wide variety of companies from open source "pro web" to Google and Alibaba might be better then having a pile of extremely wealthy firewall supporting companies.
A bunch of Chinese companies is essentially the viewpoint of the current dictator of China, should he choose to weigh in.
the concept of wasm doesn't really fly with zero-trust internet
Any website can already do that with asm.js. WASM does not change the security model of browsers.
Until such a creation comes to be, the OpenJDK JVM will continue to thrive.
for example you can get angular debugger extension for chrome and mess with any online shop that uses this system to "adjust prices" for your cart during checkout
Probably Electron can be one of such new runtimes
Can you explain a bit more in what way you see it as legacy?
Because the JVM has some of the best GCs, and JIT + AOT compilation of any VM around. And its portability story is quite impressive.
You can argue Java as a language has some legacy hanging around, though they've made great progress there with the latest versions. But the JVM has support for other languages as well, such as Ruby, Python, Scala, Kotlin, Clojure, Common Lisp, JavaScript, Fantom, etc.
Now WASM isn't a runtime. WASM is more akin to Java Bytecode or LLVM bitcode.
Each browser vendor will implement their own WASM VM. Currently, there is no standard for Garbage Collection, which means GCed languages won't be good candidates for WASM. If you want to use Python, Java, C#, Kotlin, TypeScript, Haskell, etc. your resulting program will need to bundle a full runtime for your language compiled to WASM as well. In all cases, this will end up having slower performance, and on the web will cause bigger download sizes.
Hopefully, this gets addressed in the future.
The flip side is portability. For example, Go compiled to WASM could run on all WASM non-web compliant VMs. But it'll run slower than GO compiled for the target machine directly.
That's why a good use case for WASM right now is to allow JavaScript to make use of C/C++ libraries in the browser. As well as Node.js to do the same in non-browser contexts.
This will often mean an HTML/CSS/JS UX with certain section of it in C/C++/Rust.
It does mean that Electron apps will be able to make use of portable C/C++ libraries more easily, as they get compiled to WASM and the V8 runtime will be able to run that WASM and eventually offer interop with the DOM and JS. Though that's not yet supported, as the boundary between GCed JS/DOM and WASM hasn't been fully figured out yet.
Also, WASI is the standard library for WASM, and that'll need to grow as well. Progress is being made there too, but its goal is to remain minimal, and delend more on libraries.
Conclusion, let's say you have WASM, Java Bytecode and LLVM bitcode, and maybe even .net IR. All of them are a form of virtual assembly which need a VM to run them. Any language could build a compiler to any of these. But they have different trade offs.
Java Bytecode is pretty simple, and the VM has a standard memory model and GC with a large accompanying library, and a state of the art JIT. Making it a great target for higher level languages.
.net IR is pretty similar, though the bytecode can be a bit more difficult in its handling of reified generics. That can make it a bit harder to target for higher level languages. Its JIT isn't as sophisticated, same as its GC, but it comes real close, and has good tooling around it and an excellent standard library.
LLVM will remain king for high performance, as it is designed to handle all kind of optimizations, and support multiple's language feature set efficiently. That said, it isn't as portable and isn't optimized for small binaries and fast parse times. It too, is best for low level languages as it doesn't enforce a memory model.
WASM also doesn't enforce a memory model, making it a great target for low level languages. It is optimized for safety and portability. Which means it'll most likely always be slower than LLVM. But it also tries to be as fast as it can, and theoritically could beat out Java Bytecode or .net IR given it can avoid GC overhead. It also is optimized to be streamed over the wire, that means small binaries that can be quickly parsed. So ideal for code that you can't predict where it is going to run, like the web.
The VM landscape overall is looking pretty healthy. But I think there's misconceptions out there, especially around the JVM and .net Core, and also about people's hype for WASM. Specifically, the JVM and .net Core are almost impossible to beat for what they do. So don't expect better from WASM. Similarly, JS is almost impossible to beat for what it does, and WASM doesn't plan to replace it, but enhance it.
Unless screen readers can now dive down into the canvas layer?
Besides, people mostly do not use Java because of the JVM, so I don't think WA will even make a dent on it. It's more likely that Java gets ported into WA than that WA kills it.
Toolchains like clang and g++ should be able to generate WASM directly, I don't understand why you need so many things like bynaryen to make a WASM file. Having tools is essential if you want a technology to progress towards adoption.
EDIT: actually clang can now generate WASM. I'm not curious how feasible it would be to package python with WASM