342 points · by wiqar · 5y ago · 161 comments
With a bytecode like wasm, you can create an "app runner" program that's at least an order of magnitude less complicated than current browsers. Just ship apps as wasm binaries with a simple interface (maybe WASI, haven't taken the time to dig into it yet) for requesting/providing filesystem, networking, graphics, etc resources (if you think this sounds like java, see [0]).
And I think there's room for diversity here. I can imagine a world where it's normal to have 3-4 different app runners installed on your system. Developers would target one of these runners for their app, depending on needs (performance, GUI libs provided, security guarantees, etc), and tell you which app runner you need for the app.
[0]: https://steveklabnik.com/writing/is-webassembly-the-return-o...
To give proof by counterexample, the "simple wrapper" is a graphics stack like GTK alongside the POSIX APIs. It turns out this is insufficient for application development.
Some things you're missing are text layout and accessibility. Neither are small or simple.
The browser is the new OS and they're big and complicated like OSes by necessity, not accident.
Let's keep the sandbox as simple as possible. We can build complexity inside it, and not make complexity part of it. This makes security guarantees much simpler.
While technically, complexity is not necessary, pragmatically the sandbox offers next to nothing for users or developers without OS vendors enforcing its usage, or the sandbox being so compelling a target for developers they accept the limitations of the sandbox - which is why the only platforms with robust sandboxes are mobile and the browser.
Replicating a significant fraction of the functionality of a browser ends up being a lot of code and data. For a web-like experience with instant navigation between apps it will be necessary for these shared libraries to be really shared, as in almost all apps use the same libraries and the same version of those libraries. Otherwise you'd be downloading and unpacking and JIT compiling dozens or hundreds of megabytes of code and data before you could display a single line of text, every time you click a link to a new site. The linkable nature of the web would be lost. (Yes, many websites are dozens of megabytes already, but the bulk of that is delay-loaded and happens in the background after the initial content is displayed).
In order for the standard libraries to be actually shared, everyone would have to agree on the standard libraries to use, and the standard libraries would have to be designed to be backwards compatible so that older sites could be force-upgraded to use newer versions. This is essentially the role that browser updates play today. But the browser evolved over decades and it's not clear how you'd get everyone to adopt a new set of standard libraries today, nor how you'd get everyone to agree on what functionality to add over time (the role that W3C plays today).
For libraries outside of the standard set, it sounds tempting to allow them to be shared too. But this is actually an unavoidable privacy violation. If you have a shared cache, then any app can discover the set of previously loaded libraries with a timing attack, thus revealing information about the user's browsing history. This is why all browsers are now moving to partition all caches by site: https://www.jefftk.com/p/shared-cache-is-going-away. Even if multiple sites reference the same wasm blob, it must be downloaded and JITed separately with no sharing.
As I said, I like the vision of a tiny low-level runtime executing shared libraries inside a sandbox. But I'm not sure how it could be done in an efficient and privacy-respecting way if you want to replace the Web with it.
I think we can expose standardised APIs to applications for this stuff, but the API will probably need on the order of hundreds of methods.
Speaking of moving complexity into sandboxed code, browsers could potentially run js engines inside the wasm vm, reducing a lot of complexity there.
People have been trying to create a simple, native, platform-agnostic GUI layer for as long as GUIs have existed. Nothing but the web has ever come close to succeeding. It may be a flawed solution, but it's what we have, and it works, and I wouldn't hold my breath for a greenfield alternative supplanting it any time soon.
(a) AWT was shitty and Swing an overengineered mess.
(b) GTK+ was never decent cross platform.
(c) QT was more decent, but had its own issues, and still in an uncanny valley (neither native enough, not its own thing like the web UI is).
(d) Cocoa and whatever Windows has this week are not cross platform.
(e) Most other alternatives are buggy, understuffed, and just don't look good
(f) It's easy to put something on the screen with not even a compiler or download needed.
I'm not saying we couldn't do better - the CSS API has a lot of warts and the DOM has performance issues if you don't know how to avoid them - but I am saying we had decades to do better and didn't, so there must be something very difficult about doing better and we shouldn't discount the only thing that's ever really succeeded.
Second, there were a bunch of alternatives and the Web won instead of them and not just because they weren't there.
I know, some people like running around telling everybody Qt, GTK, Swing or whatever were or even are better, but they are seemingly not for the points that matter for most of GUI apps.
But yes, we should make something better going forward.
But GUI applications are a whole different thing. The standards simply don't exist to make that easy. It's not just basic graphics. Things like internationalized text rendering, text input, and accessibility are ridiculously hard and only a few mostly-complete implementations exist. (Such as in browsers and operating systems.) And they need to keep moving as the culture changes; you want to support the latest emojis, right? Well maybe you don't, but your users will.
Furthermore, these implementations are at least partially specific to particular programming languages. If you want something portable, you might build on the Skia graphics library but that won't give you a way to build an app on its own.
For example: navigation (back, forward, refresh, etc), URLs, permission management, text search, image/video rendering, scrolling, credential management, etc; the list goes on.
That isn't to say there couldn't some day be a simpler alternative to the web offering similar features; but it has some pretty stiff competition. The only thing that even comes close today are modern operating systems like iOS and Android; and none of those are open standards like the web is.
(And the nonportability of images is another thing)
I think Wasm has the potential to become the lingua franca for software. It allows containerization in a much lighter way than virtualization (KVM), but also in a platform-agnostic way.
We have a very interesting future ahead of us!
We had this. ActiveX, Flash, Director, Air, Silverlight, Java. It was a mess, and I think you'd be hard pressed to find very many folks who found it desirable.
And to be honest, I think Flash was killed before there was a suitable replacement to fill the gap. It took more than 10 years since it "died" to actually get rid of it, because HTML5 isn't actually up to the task.
I think the fact that it survived so long proves there's a use for these types of runtimes.
A) enterprises don't upgrade or move away from technologies period (we still support IE11 and old Windows Server deployments at my current company).
B) Flash the authoring tool never got replaced. It's not about whether or not HTML5 is up to the task of being a Flash-equivalent runtime, nobody built a replacement for Macromedia/Adobe Flash targeting any runtime anywhere. To this day, there is not a vector animation tool on par with Flash for any platform, and that has nothing to do with the capabilities of the web.
People blame HTML5 when what really happened was Adobe abandoned their authoring tools and nobody built an alternative because we expected the W3C or somebody to do it for us. But a programming language will never be a replacement for a full-featured content creation tool and IDE.
Even WASM is not going to replace Flash unless some company or group somewhere actually sits down and writes a native program that can target it and that is actually competitive with what Flash the authoring tool offered devs. I have not seen serious effort in that direction, so if you're hoping WASM just magically makes these problems go away, I'm a little less optimistic about that. WASM is just going to be another runtime target -- a good one, but not a replacement for an IDE.
Browsers have been picking up the slack where OS and desktop developers have fallen down. The OS is supposed to handle process isolation and resource access, but here we are. Tabbed browsing became a thing because GUI toolkits didn't do multiple app instances (or MDI) in a way people liked.
Now, as the internet clams down a bit, the OS handles everything natively, including the security primitives (at least on mobile) and so the purpose of the browser is sadly diminishing. It's a less useful experimental side channel to the OS.
That sounds great right now, when the APIs are relatively small, but will quickly become a nightmare when they grow in complexity.
I mean, technically any browser that implements the right stuff can run any web page on earth, yet somehow we still manage to have incompatibilities even when there are only 3 implementations. Or how about POSIX? How much software needs no special casing to run on all POSIX systems?
This is the pattern: we abstract things farther with the (mistaken) belief that it will save us from having to deal with messy reality, but as soon as you try to do anything more than simple stuff you find that reality is, in fact, a mess and you have to work around your abstraction to deal with it.
Full disclosure: I am a developer, and I use and always used Firefox, for both pragmatic and ideological reasons.
Mobile firefox lacks simd, i haven't been able to get its shared memory to work on a local or deployed environment because of bugs in what it thinks is a 'secure context'
Desktop and mobile Firefox does not support OffscreenCanvas without turning on flags. It's been years since this was meant to be made. Therefore you cannot use seperate threads to render to webgl without using less performant workarounds.
Lack of proper threading means bad page performance.
There's lots more dumb bugs and features firefox said it would support and simply never did. Understand there's real reasons as to why chrome is the preferred. it works and it actually puts in the necessary features.
Too late to edit, but Steve's previous blog post probably presents my point better, though with less focus on the vs Java argument:
https://steveklabnik.com/writing/webassembly-is-more-than-ju...
This exists with e.g. shared file systems (how hpc works, how hadoop works) and Python can pickle code and send it over a socket (be aware that this is a security risk). WASM seems like a nice and direct solution for moving code to data.
The rise of javascript and its server side runtime is due to the immense pressure that language had to evolve to make the web what it is today.
Web-assembly is the next step and evolution of this runtime. I can only imagine the sheer number of man hours poured in to javascript to offer the functionality it has today while balancing with security and sandboxing. Nodejs is a different story; Take a look at Deno and its origin.
Web-assembly is sandbox-able run anywhere, ubiquitous runtime which isn't owned specifically by a corporate overlord, and is also which has/or is set to have the evolutionary pressure javascript has. This is huge! Way to go Wasmer :)
You don’t need webassembly to run C++ on the server side.
You don’t need webassembly to run Rust on the server side.
Etc.
Node was necessary because you need node (or compatible) to run JavaScript on the server side.
To quote a Docker cofounder:
> If WASM+WASI existed in 2008, we wouldn't have needed to created Docker. That's how important it is. Webassembly on the server is the future of computing. A standardized system interface was the missing link. Let's hope WASI is up to the task!
[1] https://twitter.com/solomonstre/status/1111004913222324225?s...
(unless you want to use some hacky c++ to js transpiler)
Typically client and server play different roles and require different builds anyway.
LoL, LoL, LoL
You can say this only because every other operating system sucks at sandboxing.
There is no reason you have to be inefficient as browser to provide security and sandboxing. In return there is also a huge attack surface, with all the code running below, and corner cases in web standards. AFAIK any js click event can allow a website to read your clipboard. Websites can somehow prompt to add extensions to your browser etc.. I know there are legitimate reasons for this but it sandboxing is not exclusive virtue of web platform.
Would you be confident using them to run possibly malicious code on your system?
And I won't be confident using browser too. Pretty sure at any given time there will be quite a few javascript/wasm attacks which can escape browser sandbox and run arbitrary code, then my files won't be safe. When I am running potentially malicious website I am creating a separate user on my linux box anyway.
Mainly because the areas where it used have other solutions that are “good enough”. In the browser JS is good enough. On the server Docker + your typical Linux program is “good enough”. In time things like KVM will offer great sandboxing to containers.
Another issue is that server side programs depend on system interfaces of Linux, which are battle tested, observable and trusted. With WASM you need to replicate that with some message passing system.
Running the same benchmark myself in Linux on a 4CPU VirtualBox on a MacBook Pro, I see 11s and 42s respectively. For reference , V8/Node.js compiles the same file in 27s.
Compiled files were 339 MiB (Singlepass), 640 MiB (Cranelift) and 90 MiB (V8/Node.js).
Clang.wasm itself is 45 MiB.
I noticed that certain operations take longer on a VM, and e.g. disk performance may differ a lot (and sometimes be faster than the host FS's!)
Also, things being in the page cache can speed up the second and subsequent runs much faster.
The article makes it look like compilation is almost instantaneous. It’s not. Cached artifacts are rather hefty as well.
V8 fares surprisingly well given that it’s not a specialized WebAssembly runtime. Wasmer should probably watch competitors more closely.
Why? I don't get that or maybe miss some crucial parts or maybe it's just a too enthusiastic statement. I understand the security issues of running external code. Those security issues can be reduced with a sandboxed environment like a WA runtime.
On the server side the vast majority of the industry is running their own code. There are already many options like lambda-functions, hosted container environments, hosted VMs or of course running your own. So why take this extra step? Running plain binaries of your code is easier, faster and more reliable. Building, distributing and running a Go service is actually one of the easiest parts in the whole development and operations chain. Same is true for Rust or .NET Core. Even with Java where you need a runtime I don't see how a WA runtime solves a problem at all when running your own code.
I see great potential where you need to run untrusted code. Customer plugins for some edge server. But that is really a niche in terms of overall market.
I dont know if doing this directly and cross platform is as easy without wasmer
Purpose-built sandboxing means you can run untrusted code more safely — e.g. at the network edge, like a Cloudflare worker, a lambda, etc. Same for third-party plugins in apps, etc.
An open standard and open implementations gives you some assurance against lock-in, licensing changes, patent suits, etc.
I say this as a Kotlin/Java developer. I know and love the jvm but it's just not a lightweight option suitable for edge computing or serverless computing (it works but the jvm startup overhead + binary size is annoying).
And I know nothing about browsers, GUI and front-end stuff, but Web-assembly is never the less very interesting for me, and I consider it the biggest thing since Docker.
Can someone explain why you'd want to use a wasm runtime in that context instead of just using seccomp for that ?
Is WebAssembly really faster or lighter than virtualization? Or is this about the virtual os you run in Docker?
There is a proposal [1] for adding sockets to WASI.
This blog post [2] has some more background info.
Outside the browsers, you can always provide extra functionality yourself though by supplying host defined functions as imports. That looses the benefit of a standard API, but is fine for custom deployments.
[1] https://github.com/WebAssembly/WASI/pull/312
[2] https://radu-matei.com/blog/towards-sockets-networking-wasi/
"Implementing a server requires additional API functions exposed - specifically, sock_bind, sock_listen, and sock_accept"
"And while implementing them is done similarly to what was described here so far, there is an underlying issue: there is no multi-threading support in WebAssembly"
Really surprised to see so many people talking this up to running many/most server-side applications with so many fundamental features missing.
In general I have to agree that WASM needs more time. There are multiple quite crucial proposals in the pipeline (reference types, interface types, threads, tail calls and other advanced control flow, module linking, (GC), ...) which have all seen very slow progress.
Overall I'm still bullish on the potential of WASM for universal deployment, but the slow pace is a bit concerning.
WASI, the posix-like system interface ABI, is still technically a "snapshot", which has made me slightly concerned wrt stability given that Rust can compile to WASI even on the stable channel, but hopefully even the full stable version is backwards-compatible with snapshot-1.
> some non-MVP features are almost stable
> the posix-like system interface ABI, is still technically a "snapshot"
So... It's not production ready.
They are saying the core is production ready (if your needs are met by the features included in the MVP), but that planned additional features are not yet production ready.