WebAssembly and React: A New Era of High-Performance Web Applications

Rate this content
Bookmark
Slides

Hold on, WebAssembly on the server?! I thought it was for browser!

In this talk, we'll explore the benefits of using low-level languages on the server-side, and the different possibilities that WebAssembly provides for building high-performance web applications. We'll dive into different providers for WebAssembly functions, as well as practical use cases for integrating WebAssembly with React.

By the end of this talk, you'll walk away with a deeper understanding of how server-side WebAssembly and React can be used together. You'll also gain practical insights into how to use low-level languages on the server-side, and tips for overcoming common challenges when integrating WebAssembly with React.

This talk has been presented at React Day Berlin 2023, check out the latest edition of this React Conference.

Watch video on a separate page

FAQ

WebAssembly, abbreviated as Wasm, is a binary instruction format for a stack-based virtual machine. It's designed as a portable compilation target for programming languages, enabling deployment on the web for client and server applications.

No, WebAssembly is not a programming language. It is a standard for low-level bytecode and serves as a compilation target for other programming languages to enable their execution in web browsers and other environments.

Yes, WebAssembly can run server-side applications through the WebAssembly System Interface (WASI), which provides access to system features like files, file systems, and sockets, allowing WebAssembly to run virtually anywhere.

WebAssembly is used for running both complex software and games in the browser, like old DOS games via DOSBox or image compression algorithms in Squoosh. It's also used in server environments and for cloud applications, enhancing performance and security.

WebAssembly enhances security by operating in a sandbox environment where each system call is declared at startup. This capability-based security restricts operations to what is explicitly permitted, mitigating potential vulnerabilities.

Because WebAssembly is a low-level bytecode, it allows programs to run closer to native machine speed. Its efficient execution model minimizes overhead and can significantly enhance performance, especially in web and server environments.

Yes, you can use WebAssembly with any programming language that can compile to its binary format, such as C, C++, Rust, and Go. This allows developers to leverage existing code bases and tools in new web-based environments.

Carmen Huidobro
Carmen Huidobro
14 min
12 Dec, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

WebAssembly is a binary instruction format for a stack-based virtual machine, enabling deployment of code in languages like Go, Rust, or C++ to run in the browser. It allows for efficient image compression algorithms and whole runtimes like Node.js in the browser. WebAssembly provides a capability-based security layer and eliminates the need to worry about server setup. It is already being used by well-known organizations and platforms, and continues to evolve with upcoming features such as a component model, neural network capabilities, garbage collection, and multithreading. WebAssembly modules can be used in React and as a server tool.

1. Introduction to WebAssembly

Short description:

Hi. Welcome. Thank you for tuning in today. I'm excited to talk about WebAssembly. WebAssembly, abbreviated as Wasm, is a binary instruction format for a stack-based virtual machine. It's a compilation target for programming languages, enabling deployment on the web for client and server applications. WebAssembly is not a programming language, but a standard for low-level bytecode. It allows us to compile code in languages like Go, Rust, or C++ to run in the browser. Examples of WebAssembly in the browser include running old games through archive.org or the Wayback Machine.

Hi. Welcome. Thank you so much for tuning in today. I'm so excited to talk to you about WebAssembly. And, you know, we're online, I just, I can't see you, but I still want to get a raise of hands. Do you know WebAssembly? I see some hands up. Maybe, maybe I don't. Do you know me? Raise your hand. No, I'm just kidding.

Hi. My name is Ramon. My pronouns are he, him, co-founder of the Bad Web Site Club Free Learning Initiative and a big advocate for community and learning mutually and from a community focus. It's, just gives me life. Let's dive right in. You might have heard of WebAssembly, or I'm going to call it sometimes Wasm. Let's dive right into what it is, and who better than the official website to give us the definition. WebAssembly, abbreviated as Wasm, is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable compilation target for programming languages, enabling deployment on the web for client and server applications. And this is kind of a collaborative creation, and I'm so excited about this in particular.

But when we think about WebAssembly, I want to make a couple things clear. First of all, WebAssembly is not a programming language, and I've found myself thinking this as well. I want to go and learn WebAssembly, but I can't learn it the same way as I would say React. It's not a front-end framework that we learn and apply. What WebAssembly is is a standard for low-level bytecode. It's a compilation target, and you might think, what is a compilation target? It's something that we use a lot of the time when computing. It is a standard that we take our code, say in Go or Rust or C++, we compile it or translate it to WebAssembly, which we can then run in the browser. And I want to show you a couple of examples of WebAssembly running in the browser, which are quite fun. You might have heard of archive.org or, you know, the Wayback Machine. They have a library of old software that you can run, for example, with DOSBox in WebAssembly, like old games. By the way, small note, if you're doing a talk like this, don't go and research this, because you're going to spend a lot of time playing these games as well.

2. WebAssembly for Software Development

Short description:

Prince of Persia is still one of my favorites. WebAssembly allows running low-level, efficient image compression algorithms in the browser. It's not just algorithms, but whole runtimes like Node.js. Server-side WebAssembly with WASI allows running WebAssembly anywhere. WASI provides access to system resources without being an operating system. Wasmtime is one of the most prolific WebAssembly runtimes.

Prince of Persia is still one of my favorites. But it's not just for games. It's also for high-end software. For example, Squoosh is a software that is an online software in the browser that lets you run low-level, really efficient image compression algorithms. Now, you might think, well, can't I do that in JavaScript? And of course you can. But what's incredible about this is that it makes it possible for doing these image compressions in a really efficient way in places where JavaScript might be an unideal language for image compression. So you can take your pre-existing algorithms in C or C++ and run them in the browser.

But it's not just algorithms, it's whole run times. You might have heard of StackBlitz. This is a project that lets you do coding in the browser, but it's running a Node.js runtime in WebAssembly. Not your JavaScript engine from the browser, a Node.js runtime. And this can be as big as an entire piece of software. Some folks have got LibreOffice, if you're familiar with it. It's an open source Microsoft Office kind of software running code for code in the browser. It is a 300 megabyte download, but it's still amazing to me that you can run this in your browser.

But OK, Ramon, you've been talking about all of this browser stuff. What about server-side WebAssembly? Surely WebAssembly can't just run anywhere. And you'd be right, except the folks who have been working on this standard have been doing some incredible things. WebAssembly with a system interface or WASI allows us to have these system interfaces so that we can run WebAssembly pretty much anywhere. Now, if you're familiar with it—oh, by the way, you've got to see this guide that I've linked here from Lynn Clark. She's done this illustrated guide to WebAssembly, and it is incredible. So the way a program works is that it needs to interface with a system's resources, which a lot of the times are protected by a kernel. So the kernel will do things like give you access to your file system and other resources of your computer. So what WASI allows us to do is to have these and have these access to these system calls. But to be clear, it's not an operating system. I'm going to let them explain it better than I can. From the Wasmtime project, it's an API provided by the Wasmtime project that provides access to several operating system-like features, including files, file systems, Berkeley sockets, clocks, random numbers. It is incredible. So what you can do in currently when running programs is you take your C code, you translate it, you or compile it to elf for Linux, portable executable for Windows or Mac o for Mac, which is all well and good, but when it comes to WebAssembly, now we can take our C code, create a Wasm or WebAssembly binary, which can then be run on any operating system with this very important part here, a WebAssembly runtime. I'm going to quickly run through a couple of examples of these, because of course I mentioned Wasmtime, which is one of the most prolific ones, but there's a whole bunch of them.