Video Summary and Transcription
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
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
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.
Comments