October 10th, 2024

WASM Is the New CGI

WebAssembly (Wasm) is transforming web application development by enhancing performance, enabling efficient code execution, and addressing serverless cold start issues, despite limitations like lack of native threading and JIT compilation.

Read original articleLink Icon
ConfusionSkepticismFrustration
WASM Is the New CGI

WebAssembly (Wasm) is emerging as a transformative technology in web application development, akin to the role of the Common Gateway Interface (CGI) in the early web. While CGI allowed for the creation of interactive web applications, Wasm is set to enhance performance and ease of development for both client and server applications. The evolution of web application models has consistently aimed for high performance and maintainability, with Wasm representing the next significant shift. Unlike CGI, which involved executing scripts on demand, Wasm enables the compilation of various programming languages into a binary format that can run efficiently in both browsers and server environments. This capability allows for lightweight isolation of untrusted code, reducing the overhead associated with traditional virtual machines or containers. Wasm's architecture supports the creation of modules that can be paused and resumed, eliminating the cold start issues often faced in serverless computing. However, Wasm does have limitations, such as the lack of native threading and the inability to perform Just-In-Time (JIT) compilation, which can affect performance. Despite these challenges, the potential of Wasm to streamline web application development and execution is significant, positioning it as a key player in the future of web technologies.

- WebAssembly (Wasm) is poised to revolutionize web application development, similar to CGI's impact in the past.

- Wasm allows for high-performance applications by compiling various programming languages into a binary format.

- It provides lightweight isolation for untrusted code, reducing overhead compared to traditional VMs.

- Wasm modules can be paused and resumed, addressing cold start issues in serverless environments.

- Limitations include the lack of native threading and JIT compilation, which may affect performance.

Related

What Happens When You Put a Database in the Browser?

What Happens When You Put a Database in the Browser?

WebAssembly (Wasm) enhances browser capabilities, enabling high-performance apps like DuckDB for ad-hoc queries and Python environments. DuckDB Wasm boosts performance in interfaces like lakeFS, Evidence, and Count. MotherDuck enables local querying, emphasizing efficient data processing.

Dynamic Translation of Smalltalk to WebAssembly

Dynamic Translation of Smalltalk to WebAssembly

The article explores Smalltalk code translation to WebAssembly (WASM) within the Catalyst project. It details levels of Smalltalk, JavaScript, and WASM, focusing on direct Smalltalk to WASM optimization. A new translator, WATCompiledMethodTranslator, aids in this process, exemplified by a Smalltalk expression conversion. Creation of a WASM module for Smalltalk methods is explained, highlighting performance advantages and potential future comparisons with dynamic JS translations. Collaboration in the Smalltalk community is encouraged for further advancement.

Compilation of JavaScript to WASM, Part 2: Ahead-of-Time vs. JIT

Compilation of JavaScript to WASM, Part 2: Ahead-of-Time vs. JIT

Chris Fallin's blog post discusses his AOT compiler for JavaScript to WebAssembly, achieving 3-5x performance improvements while addressing challenges like dynamic typing and Wasm platform constraints.

Compilation of JavaScript to WASM, Part 3: Partial Evaluation

Compilation of JavaScript to WASM, Part 3: Partial Evaluation

The article concludes a series on compiling JavaScript to WebAssembly, discussing challenges, proposing a portable interpreter for debugging, and introducing the Futamura projection for program compilation and analysis.

Notes on running Go in the browser with WebAssembly

Notes on running Go in the browser with WebAssembly

Eli Bendersky's article explores integrating Go with WebAssembly, showcasing examples of calling Go functions from JavaScript, using TinyGo for smaller binaries, and employing Web Workers to maintain UI responsiveness.

AI: What people are saying
The comments on the article about WebAssembly (Wasm) reveal a range of opinions and concerns regarding its role in web development.
  • Many commenters draw parallels between Wasm and older technologies like Java Applets and CGI, questioning the security and practicality of running untrusted code in browsers.
  • There is skepticism about Wasm's advantages over JavaScript, with some arguing that it complicates deployment and debugging without significant performance benefits.
  • Some users express concerns about Wasm's impact on mobile performance and battery life, highlighting issues with heavy websites.
  • Several comments discuss the potential for Wasm to replace server-side functions, suggesting it could simplify deployment and improve performance in serverless architectures.
  • Overall, there is a mix of optimism and skepticism about Wasm's future, with some believing it will become a standard while others doubt its necessity.
Link Icon 25 comments
By @junto - 6 days
Can someone explain to me what the difference really is between WASM and older tech like Java Applets, ActiveX, Silverlight and Macromedia Flash, because they don’t really sound much different to me. Maybe I’m just old, but I thought we’d learnt our lesson on running untrusted third party compiled code in a web browser. In all of these cases it’s pitched as improving the customer experience but also conveniently pushes the computational cost from server to client.
By @tantalor - 6 days
> Amazon started the serverless age of compute with Lambda

Google App Engine (2008) predates Lambda (2014) by 6 years!

By @torginus - 6 days
Just in Time (JIT) compilation is not possible as dynamic Wasm code generation is not allowed for security reasons.

This sounds.. not right. Honestly,this is an essential feature for allowing workloads like hot reloading code cleanly.

I'm quite convinced the alleged security argument is bull. You can hot reload JS (or even do wilder things like codegen) at runtime without compromising security. Additionally, you can emulate codegen or hot reload, by dynamically reloading the entire Wasm runtime and preserving the memory, but the user experience will be clunky.

I don't see any technical reason why this couldn't be possible. If this were a security measure, it could be trivially bypassed.

Also, WASM bytecode is very similar conceptually to .NET IL, Java bytecode etc., things designed for JIT compilation.

I kind of dislike WASM. It's a project lacking strong direction and will to succeed in a timely manner. First, the whole idea is conceptually unclear, its name suggests that it's supposed to be 'assembly for the web', a machine language for a virtual CPU, but it's actually an intermediate representation meant for compiler backends, with high-level features planned such as GC support. It's still missing basic features, like the aforementioned hot reload, non-hacking threading, native interfacing with the DOM (without Javascript ideally), low-overhed graphics/compute API support, low-level audio access etc. You can't run a big multimedia app without major compromises in it.

By @jillesvangurp - 6 days
WASM replaces a language specific vm (javascript) with a general purpose one anywhere javascript vms are currently used. But not exclusively just there. General purpose here means it can run just about anything with a compiler or interpreter for it. Including javascript. So anything, anywhere.

Since it is generally implemented as part of the javascript engine, it inherits a lot of stuff that comes with it like sandboxing and access to the APIs that come with it. Standardizing access to that is a bit of an ongoing process but the end state here is that anything that currently can only be done in Javascript will also be possible in WASM. And a lot more that is currently hard or impossible in Javascript. And it all might run a little faster/smoother.

That makes WASM many things. But the main thing it does is remove a lot of restrictions we've had on environments where Javascript is currently popular. Javascript is a bit of a divisive language. Some people love it, some people hate it. It goes from being the only game in town to being one of many things you can pick to do a thing.

It's been styled as a Javascript replacement, as a docker replacement, as a Java replacement, a CGI replacement (this article), etc. The short version of it is that it is all of these things. And more.

By @fallous - 6 days
This article really does remind me of an old Law of Software that we used to invoke: Any sufficiently large and long-lived application will eventually re-implement the entire software stack it runs on, including the operating system.. and it will re-implement it poorly.

I'm unsure of the source for this Law, but it certainly proves correct more often than not.

By @layer8 - 6 days
To expand the premise in the title, to be a true heir to that lineage, I would say that WASM needs to be as easy to host and deploy as PHP applications are (or used to be) on the LAMP stack of any random hosting provider. I suspect that’s not quite the case yet?
By @cheema33 - 6 days
I have a different take on this. I think local-first is the future. This is where the apps runs mostly within user's browser with little to no help from the server. Apps like Figma, Linear and Superhuman use this model very successfully. And to some degree Stackblitz does as well.

If somewhat complex apps like Figma can run almost entirely within user's browser, then I think vast majority of the apps out there can. Server side mostly is there to sync data between different instances of the app if the user uses it from different locations.

The tooling for this is in the works, but is not yet mature. e.g Electric-SQL. Once these libraries are mature, I think this space will take off.

Serverless is mostly there to make money for Amazon and Azures of the world and will eventually go the way of the CGI.

WASM could succeed as well. But mostly in user's browser. Microsoft uses it today for C#/Blazor. But it isn't the correct approach as dotnet in browser will likely never be as fast as Javascript in the browser.

By @rpcope1 - 6 days
So basically we're reinventing the JVM and it's ecosystem?
By @DanielHB - 6 days
I have been thinking we would be heading for a world where WASM replaces code running lambda functions on the cloud for a long time. WASM is traditionally seen as running on a host platform, but there is no reason it needs to be this way.

Because of the sandbox nature of WASM technically it could even run outside an operating system or in ring0 bypassing a lot of OS overhead.

Compiling to WASM makes a whole range of deployment problems a lot simpler for the user and gives a lot of room for the hosting environment to do optimizations (maybe even custom hardware to make WASM run faster).

By @superkuh - 6 days
Anything that requires executing arbitrary untrusted code from arbitrary untrusted sources automatically is bad and is definitely not filling the same role as server side CGI.
By @openrisk - 6 days
It is challenging to forecast how client-server architectures would evolve on the basis of technical merit, even if we restrict to "web architectures" (this itself being a bundle of multiple options).

Massive scaling with minimal resources is certainly one important enabler. If you were, e.g., to re-architect wikipedia with the knowledge and hardware of today how would you do it with wasm (on both desktop and mobile). How about a massive multiplayer game etc.

On the other hand you have the constraints and costs of current commercial / business model realities and legacy patterns that create a high bar for any innovation to flurish. But high does not mean infinitely high.

I hate to be the person mentioning AI on every HN thread but its a good example of the long stagnation and then torrential change that is the hallmark of how online connected computing adoption evolves: e.g., we could have had online numerically very intensive apps and API's a long time ago already (LLM's are not the only useful algorithm invented by humankind). But we didnt. It takes engineering a stampede to move the lazy (cash) cows to new grass land.

So it does feel that at some point starting with a fresh canvas might make sense (as in, substantially expand what is possible). When the cruft accumulates sometimes it collapses under its own weight.

By @slt2021 - 6 days
putting everything in WASM really drains the battery on mobile.

I hate WASM heavy websites as often they have bloat of javascript and site is very slow, especially during scrolling, zooming due to abuse of event listeners and piss poor coding discipline.

I kinda miss sometimes server rendered index.php

By @kennu - 6 days
In my view, the big promise of server-side WASM is to have an evergreen platform that doesn't need regular updates to the application. Just like HTML web pages work "forever" in browsers, WASM-based applications could work forever on the server-side.

Currently it is a huge PITA to have to update and redeploy your AWS Lambda apps whenever a Node.js or Python version is deprecated. Of course, usually the old code "just works" in the new runtime version, but I don't want to have to worry about it every few years. I think applications should work forever if you want them to, and WASM combined with serverless like Lambda will provide the right kind of platform for that.

By @akoboldfrying - 6 days
I don't know much about Wasm so this was helpful, thanks. It does seem like having the same language on both server and browser must make software delivery more flexible.

>Just in Time (JIT) compilation is not possible as dynamic Wasm code generation is not allowed for security reasons.

I don't follow -- is the Wasm runtime VM forbidden from JITing? (How could such a prohibition even be specified?) Assuming this is the case, I'm surprised that this is considered a security threat, given that TTBOMK JVMs have done this for decades, I think mostly without security issues? (Happy to be corrected, but I haven't heard of any.)

By @smolder - 6 days
I kind of like this variety of headline for it's ability to stimulate discussion but it's also nonsense. CGI can be any type of code responding to an individual web request, represented as a set of parameters. It has basically nothing to do with wasm which is meant to be a universal code representation for a universal virtual machine. Have I missed something?
By @wokwokwok - 6 days
What the article actually says:

> If we go back to thinking about our Application Server models; this allows us to have a fresh process but without paying the startup costs of a new process. Essentially giving us CGI without the downsides of CGI. Or in more recent terms, serverless without cold starts. This is how Wasm is the new CGI.

^ It's not a frivolous claim.

> Wasm improves performance, makes process level security much easier, and lowers the cost of building and executing serverless functions. It can run almost any language and with module linking and interface types it lowers the latency between functions incredibly.

^ Not unreasonable.

I don't agree that its necessarily totally 'game changing', but if you read this article and you get to the end and you dont agree with:

> When you change the constraints in a system you enable things that were impossible before.

Then I'm left scratching my head what it was you actually read, or what the heck you're talking about.

> Serverless is mostly there to make money for Amazon and Azures of the world and will eventually go the way of the CGI.

There's... just no possible future, in which AWS and Azure just go away and stop selling something which is making them money, when a new technology comes along and makes it easier, safer and cheaper to it.

> I kind of like this variety of headline for it's ability to stimulate discussion but it's also nonsense. CGI can be any type of code responding to an individual web request, represented as a set of parameters. It has basically nothing to do with wasm

*shakes head sadly...*

...well, time will tell, but for alllll the naysayers, WASM is here to stay and more and more people are using it for more and more things.

Good? Bad? Dunno. ...but it certainly isn't some pointless niche tech that no one cares about is about to disappear.

CGI enabled a lot of things. WASM does too. The comparison isn't totally outrageous. It'll be fun to see where it ends up. :)

By @anonu - 6 days
I like the thought. I also think about how Python losing the GIL. If we can write Python to WASM and maintain multi-threading, then the browser is sort of the new "Java JRE"... (to expand on the analogies)
By @throwaway313373 - 6 days
> The Rack web server interface from the Ruby community eventually made into python via the Flask application server and the WSGI specification.

It's amazing how just one sentence can be so utterly wrong.

WSGI actually predates rack by several years: first WSGI spec was published in 2003 [0], rack was split from Rails in 2007 [1].

Flask is not an "application server", it is one of the web frameworks that implements WSGI interface. Another popular framework that also implements it is Django. Flask is not the first WSGI implementation, so I'm not sure why author decided to mention Flask specifically. It's probably one of the most popular WSGI implementations but there is nothing special about it, it hasn't introduced any new concepts or a new paradigm or anything like that.

I'm not sure if the rest of the article is even worth reading if the author can't even get the basic facts right but for some reason feels the need to make up total nonsense in their place.

[0] https://peps.python.org/pep-0333/

[1] https://github.com/rack/rack/blob/main/CHANGELOG.md

By @feverzsj - 6 days
Companies choose wasm to avoid crawlers.
By @EGreg - 6 days
WASM runs on the client side.

WASM is basically the new Microsoft Common Language Runtime, or the new JVM etc.

But OPEN!

By @tantalor - 6 days
[2022]
By @Tepix - 6 days
I disagree. In particular for me the allure for CGI was its simplicity. Have you played around with WASM in the browser? It involves way too many steps to get it integrated into the web page and to interact with it.

I let chatgpt do the tedious work, have a look at a minimal example:

https://chatgpt.com/share/6707c2f3-5840-8008-96eb-e5002e2241...

By @TekMol - 6 days
I don't see WASM as a significant step forward. In fact, I question its purpose altogether.

Before WASM you could already compile code from other languages into JavaScript. And have the same benefits as you have with WASM.

The only benefit WASM brings is a bit faster execution time. Like twice the speed. Which most applications don't need. And which plain JavaScript offers about two years later because computers become faster.

And you pay dearly for being these two years ahead in terms of execution time. WASM is much more cumbersome to handle than plain JS when it comes to deployment, execution and debugging.

In IT we see it over and over again that saving developer time is more important than saving CPU cycles. So I think chosing WASM over plain JS is a net negative.