Okay, what are some of the lessons learned? So I've been using WebAssembly since 2018 for sandbox.bio, but also for other tools and applications where WebAssembly was really useful. I wanted to talk about the opposite side of it, which is when I wouldn't use WebAssembly. And the first place is if you're doing too little or too much computation. I know that that sounds kind of meaningless, but let's talk about what those look like.
So too little computation. The best example for that is if you're using a library that lets you design your front-end UI in Rust, and it gets compiled to WebAssembly. Look, I get it. That's very cool, but it's not really practical. You end up embedding a lot of HTML and weird-looking JavaScript into this, and it's not clear to me what the benefit is. Your application will definitely not be faster. I mean, if your UI is that slow, you kind of need to rethink what you're doing. And what you might want to do is look at the slow parts only and replace those with WebAssembly instead of using WebAssembly for the whole application, which makes less sense. Because there's also going to be a lot of overhead, especially mental overhead, as you're trying to figure out how you're compiling this stuff to WebAssembly. And also, probably other people on your team who use JavaScript don't know how to use Rust. That's an extra amount of overhead that I don't think is really worth it. But it is cool, so I'll give you that.
On the other end of the spectrum is too much computation. So if you're using more than four gigs of RAM, for example, or if you need something that needs to run at 100% CPU for minutes or even tens of seconds, you may want to rethink whether that's the right user experience that you want to provide your user. And maybe it just makes sense to run this task on the cloud.
On the other hand, what I've found to be the sweet spot is when you do things like playgrounds, like Sandbox Bio does, small-scale simulations, audio and video processing, and upload pre-processing. And this is one that I've used several times, where if you ask users to upload very large datasets, while the data is being uploaded, you can run some sanity checks on the data. And you can do this in JavaScript too, but in my case, a lot of the tools for doing this sanity check was written in C for bioinformatics, and so it basically brought it to the web with WebAssembly. But so in general, in my opinion, WebAssembly is really best for reusing existing code that isn't written in JavaScript and you want to bring it to the web, or just sprinkling it in for a little bit of improvements here and there. That's when I found it to be most powerful. And it's also worth saying too, WebAssembly is not the kind of tool that every developer should be using. It only makes sense in a few subset of cases, and if it doesn't make sense for your use case, I would just say don't bother. It's a niche technology, that's for sure. Another reason I wouldn't use WebAssembly is trying to replace containers. And if you look at what is happening in the world of WebAssembly right now, you'll see a lot of excitement about using WebAssembly outside the browser. In some cases, some people will say that WebAssembly is going to destroy Docker containers, which honestly I'm a bit confused by because I'm not sure what that means.
Comments