High Performance Node.js Powered by Rust and WebAssembly

Rate this content

In the post Moore’s Law era, due to limitations of the hardware, we need to squeeze more performance from the existing hardware. That means that the native code provides the best performance. However, the prevalence of native code on the server-side presents challenges to application safety and manageability. The rise and advent of Rust and WebAssembly offers new ways for developers to write high performance yet safe Node.js applications.

In this talk, I will cover the basics of Rust and WebAssembly, as well showcase how to go about their integration with Node.js. You will learn how and when to design a hybrid web application. How can you code the high performance functions in Rust in a Web Assembly virtual machine and finally how to tie everything together in a Node.js JavaScript application.

8 min
18 Feb, 2022


Sign in or register to post your comment.

AI Generated Video Summary

This talk explores using Rust and WebAssembly to enhance the performance of Node.js applications. By leveraging Rust's efficiency and safety features, and compiling it into WebAssembly bytecode, developers can achieve high-performance computations while ensuring security. WebAssembly enables direct communication with native hardware and is optimized for server-side applications, making it suitable for tasks like AI inference and storage databases. Overall, this talk highlights the potential of combining JavaScript, Rust, and WebAssembly to build performant and portable applications.

1. Introduction to High Performance Node.js

Short description:

Hello, everyone. I'm Shivai Lamba. Today my lightning talk at Node.js Congress 2022 is on high performance Node.js powered by Rust and WebAssembly. The Moore's law states that the number of transistors on a microchip doubles every two years. To overcome hardware limitations, we need to improve software performance while ensuring safety and security. Rust is a safe and modern programming language that offers efficiency and superior performance compared to NodeJS. We can use WebAssembly to compile Rust code into bytecode and manage it with a virtual machine. WebAssembly provides security, lightweight and portable runtime, extreme efficiency, and runtime safety. This talk focuses on using JavaScript, Rust, and WebAssembly to build applications with the performance of Rust and the safety and portability of WebAssembly.

Hello, everyone. I'm Shivai Lamba. I'm currently TensorFlow.js special interest group member and also a working group member from India. And I'm also a mentor for TensorFlow, specifically for TensorFlow.js.

And today my lightning talk at Node.js Congress 2022, it's going to be on high performance Node.js powered by Rust and WebAssembly. Now first, let's briefly talk about the Moore's law. Everyone knows that the Moore's law stated that the number of transistors on a microchip doubles every two years. But if you sort of see from the previous past five years, the size limitation that has caused, has sort of limited the amount of transistors that can be set in a chip. And that has sort of resulted in a plating effect of the performance of a computer hardware. So that means is that in order to be able to overcome this limitation done by the hardware, we have to improve the software with the help of practices of improving software performance. And at the same time, these software improvement performances have to also be safe and secure at the same time.

So for that, we are going to be looking at a few tools that you can use with a lot of different server-side applications and languages such as NodeJS and Rust. Now, why to choose Rust? We have a lot of legacy programming languages like C++, but these are specifically error-prone. But Rust provides a safe, modern and is also equally, if not the same as C++ in terms of efficiency. And also, it is much more capable than NodeJS in terms of performance. You can really crank it up with a lot of highly demanding performance applications that can run very simply with the help of Rust.

And then, the question arises that how can we actually use Rust to code on the web? Well, the older way was to actually compile it to the native libraries and extensions with existing runtimes like NodeJS. But this approach proved to be actually quite unsafe and also required a high amount of maintenance. So, what's the better way? Well, you can use WebAssembly, which is essentially a way to be able to... it provides the instructions to be able to use bytecodes that help interact with the application that you're running it on, specifically the web, with the lower-level applications that you're running on the platform. And we are able to just compile the Rust code into bytecode and then manage it with the help of a virtual machine such as WebAssembly. And what are some of the benefits of WebAssembly virtual machine, which today is also known as Wasmage's runtime? Well, it provides a lot of security out of the box. It is extremely lightweight and portable. It provides extreme efficiency because it uses techniques such as ahead-of-time compilation. It also provides runtime safety as well. And it's specifically optimized for a lot of different server-side applications. And that sort of brings us to the ecosystem that we have for this talk. That we want to use JavaScript for its ease of use to be able to build applications while also have the performance of Rust and have the safety and portability of something like WebAssembly. And that sort of brings us to this architecture that we have. So generally, Node.js runtimes will be based on C++-based runtime.

2. Using WebAssembly for High Performance

Short description:

We can use a WebAssembly-based virtual machine to run Rust-based programs with highly computational tasks, making Node.js applications more efficient. By writing intensive tasks in Rust and using JavaScript functions to call WebAssembly-based functions, we can bundle and compile Rust functions into bytecode hosted on the WebAssembly virtual machine. This not only secures the application but also enables high-performance computations with Rust. WebAssembly can be used for various tasks, including AI inference and storage databases, as it allows direct communication with native hardware and is optimized for server-side applications.

But of course, we have the alternative solution to be able to essentially have a WebAssembly-based virtual machine which can run the Rust-based programs that have the highly computational tasks in them and that can help to make Node.js-based applications highly efficient. And let's see how that actually works. So what we're doing is that we have our Node.js application where all the highly intensive tasks are not written in Node.js but they are actually written in Rust. So with the help of a JavaScript function, we'll be calling the WebAssembly-based functions that help to bundle up the Rust function and compile it into a bytecode that is then served and is actually hosted on the WebAssembly virtual machine, in this case, Wasmx or the SSVM. And that helps to not only secure the application but also all these highly intensive competitions that need to take place are now being done with the help of Rust. And you just have to simply call this function with the help of your Node.js environment. And of course you can use them for a lot of different things, including AI inference, because you're able to directly actually communicate with the native hardware that is your AI hardware or you can use them for things like storage databases as well since WebAssembly is highly optimized for server-side applications.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

React Advanced Conference 2022React Advanced Conference 2022
25 min
A Guide to React Rendering Behavior
React is a library for "rendering" UI from components, but many users find themselves confused about how React rendering actually works. What do terms like "rendering", "reconciliation", "Fibers", and "committing" actually mean? When do renders happen? How does Context affect rendering, and how do libraries like Redux cause updates? In this talk, we'll clear up the confusion and provide a solid foundation for understanding when, why, and how React renders. We'll look at: - What "rendering" actually is - How React queues renders and the standard rendering behavior - How keys and component types are used in rendering - Techniques for optimizing render performance - How context usage affects rendering behavior| - How external libraries tie into React rendering
React Summit 2023React Summit 2023
32 min
Speeding Up Your React App With Less JavaScript
Too much JavaScript is getting you down? New frameworks promising no JavaScript look interesting, but you have an existing React application to maintain. What if Qwik React is your answer for faster applications startup and better user experience? Qwik React allows you to easily turn your React application into a collection of islands, which can be SSRed and delayed hydrated, and in some instances, hydration skipped altogether. And all of this in an incremental way without a rewrite.
Vue.js London Live 2021Vue.js London Live 2021
8 min
Utilising Rust from Vue with WebAssembly
Rust is a new language for writing high-performance code, that can be compiled to WebAssembly, and run within the browser. In this talk you will be taken through how you can integrate Rust, within a Vue application, in a way that's painless and easy. With examples on how to interact with Rust from JavaScript, and some of the gotchas to be aware of.
React Summit 2023React Summit 2023
23 min
React Concurrency, Explained
React 18! Concurrent features! You might’ve already tried the new APIs like useTransition, or you might’ve just heard of them. But do you know how React 18 achieves the performance wins it brings with itself? In this talk, let’s peek under the hood of React 18’s performance features: - How React 18 lowers the time your page stays frozen (aka TBT) - What exactly happens in the main thread when you run useTransition() - What’s the catch with the improvements (there’s no free cake!), and why Vue.js and Preact straight refused to ship anything similar
JSNation 2022JSNation 2022
21 min
The Future of Performance Tooling
Our understanding of performance
user-experience has heavily evolved over the years. Web Developer Tooling needs to similarly evolve to make sure it is user-centric, actionable and contextual where modern experiences are concerned. In this talk, Addy will walk you through Chrome and others have been thinking about this problem and what updates they've been making to performance tools to lower the friction for building great experiences on the web.
JSNation Live 2021JSNation Live 2021
29 min
Making JavaScript on WebAssembly Fast
JavaScript in the browser runs many times faster than it did two decades ago. And that happened because the browser vendors spent that time working on intensive performance optimizations in their JavaScript engines.
Because of this optimization work, JavaScript is now running in many places besides the browser. But there are still some environments where the JS engines can’t apply those optimizations in the right way to make things fast.
We’re working to solve this, beginning a whole new wave of JavaScript optimization work. We’re improving JavaScript performance for entirely different environments, where different rules apply. And this is possible because of WebAssembly. In this talk, I'll explain how this all works and what's coming next.

Workshops on related topic

React Summit 2023React Summit 2023
170 min
React Performance Debugging Masterclass
Featured WorkshopFree
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)
JSNation 2023JSNation 2023
170 min
Building WebApps That Light Up the Internet with QwikCity
Featured WorkshopFree
Building instant-on web applications at scale have been elusive. Real-world sites need tracking, analytics, and complex user interfaces and interactions. We always start with the best intentions but end up with a less-than-ideal site.
QwikCity is a new meta-framework that allows you to build large-scale applications with constant startup-up performance. We will look at how to build a QwikCity application and what makes it unique. The workshop will show you how to set up a QwikCitp project. How routing works with layout. The demo application will fetch data and present it to the user in an editable form. And finally, how one can use authentication. All of the basic parts for any large-scale applications.
Along the way, we will also look at what makes Qwik unique, and how resumability enables constant startup performance no matter the application complexity.
React Day Berlin 2022React Day Berlin 2022
53 min
Next.js 13: Data Fetching Strategies
- Introduction
- Prerequisites for the workshop
- Fetching strategies: fundamentals
- Fetching strategies – hands-on: fetch API, cache (static VS dynamic), revalidate, suspense (parallel data fetching)
- Test your build and serve it on Vercel
- Future: Server components VS Client components
- Workshop easter egg (unrelated to the topic, calling out accessibility)
- Wrapping up
Node Congress 2023Node Congress 2023
109 min
Node.js Masterclass
Have you ever struggled with designing and structuring your Node.js applications? Building applications that are well organised, testable and extendable is not always easy. It can often turn out to be a lot more complicated than you expect it to be. In this live event Matteo will show you how he builds Node.js applications from scratch. You’ll learn how he approaches application design, and the philosophies that he applies to create modular, maintainable and effective applications.
: intermediate
Node Congress 2023Node Congress 2023
63 min
0 to Auth in an Hour Using NodeJS SDK
Passwordless authentication may seem complex, but it is simple to add it to any app using the right tool.
We will enhance a full-stack JS application (Node.JS backend + React frontend) to authenticate users with OAuth (social login) and One Time Passwords (email), including:
- User authentication - Managing user interactions, returning session / refresh JWTs
- Session management and validation - Storing the session for subsequent client requests, validating / refreshing sessions
At the end of the workshop, we will also touch on another approach to code authentication using frontend Descope Flows (drag-and-drop workflows), while keeping only session validation in the backend. With this, we will also show how easy it is to enable biometrics and other passwordless authentication methods.
Table of contents
- A quick intro to core authentication concepts
- Coding
- Why passwordless matters
- IDE for your choice
- Node 18 or higher
JSNation Live 2021JSNation Live 2021
156 min
Building a Hyper Fast Web Server with Deno
Deno 1.9 introduced a new web server API that takes advantage of Hyper, a fast and correct HTTP implementation for Rust. Using this API instead of the std/http implementation increases performance and provides support for HTTP2. In this workshop, learn how to create a web server utilizing Hyper under the hood and boost the performance for your web apps.