Why I Think WebAssembly is a Bad Idea
Sounds pretty cool right? Well, that's not all - a lot of big names are using WebAssembly including Disney+ and Shopify. There's a growing list of projects using WebAssembly at https://madewithwebassembly.com/
So, if I'm telling you about a new way of writing code for the web that's quicker, more portable, and lets you use the language of your choice... why do I think it's a bad idea?
Well, we've been here before. More than once. We've been here with Java Applets. We've been here with ASP.net. And Flash. And Silverlight. In fact, it's one of the negative patterns that we just don't seem to be able to break in computer programming; we take a working client-server model and we try to make the client fatter and thicker and get it to do more heavy lifting. Then, after a while, we realize the error of our ways and we break things apart again.
We did it with the PC. We did it with the smartphone. We did it with wearables.
We just can't stop trying to load more processing and activity into the client-side, a pattern that always ends up being reversed.
Yes, WebAssembly is good at "heavy lifting"
But where you do your heavy lifting matters...
However, this makes the fundamental assumption that every client device has enough computing power to do what we want it to do. In a world where we have a shortage of microprocessors that is likely to last for another few years, increasing costs, and lower-powered devices (like Chromebooks) becoming more popular, why are we trying to push processing back on to clients again?
Web Assembly for Serverless Computing
There's a lot of buzz about "serverless computing" at the moment, but for me that doesn't mean pushing processing back to the client-side. Serverless computing means running code in the cloud without having to invest in a whole server to do it. It's about time-slicing a much bigger machine into much smaller increments than we currently do by allowing us to grab some resource on an "as we need it" basis from a large pool rather than ring-fence a chunk of resource and then waste it when we're not using it.
Even an elastic server will waste resources, running at its smallest possible size while idle is still running. Serverless computing allows us to "scale to zero" - zero running costs when we are not running.
The AutoCad web app is a far better example (although not as clearly explained as the Cloudflare proof of concept). Here, all the heavy lifting is done remotely so your system requirements are minimal. WebAssembly is a good choice for this as CAD is computationally expensive and has, historically, needed some beefy client-side hardware to run.
As a way of delivering more complex code and allowing it to run fast on a low-powered device, by leveraging external resources, this model makes sense and is scalable for the future. Moving complex processing client-side isn't a good idea, unless you absolutely have to.
Mostly, it comes down to bandwidth
One of the things that people say that they want to do with WebAssembly is make games that run quickly in the browser. Sounds cool... except we already have this, and it's called Stadia. Stadia is Google's streaming games platform, an environment where the game (the heavy lifting) runs remotely and streams the video and audio to your computer. Stadia makes it possible to run even incredibly complex and resource-hungry games, such as Cyberpunk 2077, on relatively lower-powered hardware (like my four-year Chromebook). I don't care how fast WebAssembly might think it is, but when the game recommends a $400 graphics card as its minimum spec, that game is not running in a browser on a Chrombook. Ever.
The only obstacle to improving the performance of server-side computing of this sort is bandwidth and this is one area of computing where we still see exponential improvement in capacity coupled with falling prices. (And yes, there is such a thing as 6G...)
Should I use Web Assembly?
If I haven't made it clear enough yet, there's one good use case for WebAssembly right now and that's if you've got heavy lifting to do. The other oft-touted reason to use WebAssembly is that it lets you write in a wider variety of languages than you currently can for the web. Sadly, this is a lie... and not a very useful one.
What's the future for WebAssembly?
Everyone said node.js would kill PHP. As of January 2022, PHP still runs 77.8% of the web.