Creating Node.js libraries with Rust using Neon (Twitch live stream)

Subscribers:
950
Published on ● Video Link: https://www.youtube.com/watch?v=jkC4vik8__k



Category:
Tutorial
Duration: 1:16:07
600 views
11


In this live stream, we explore the Neon project, a tool that allows you to create Node.js libraries from Rust.

We'll take a look at Neon docs and follow the quickstart tutorial. We'll review the generated code and explore the concept of handle and JS values. Don't worry, we'll make sure to explain everything in simple terms so everyone can follow along!

Then, it's time to get our hands dirty and create a function to sum 2 numbers and a function to sum the square of an array of numbers. We'll even figure out how to downcast a generic JsValue to a JsNumber.

But that's not all! We'll complete and test our implementation while handling casting errors correctly. We'll benchmark against a pure JavaScript implementation, find a bug, and fix it. And if that's not enough, we'll try to parallelize our Rust solution using the Rayon crate.

We're not done yet! We'll test with one million numbers and reduce the data passed to Rust by passing only n as the number of items to sum (and not an entire array). And we'll make sure to explain everything in detail along the way.

So get ready to learn, have fun, and optimize your code like a pro! Let's get started!

Links:

- The Neon project: https://neon-bindings.com/
- The Rayon crate: https://docs.rs/rayon
- The repository with our code samples: https://github.com/lmammino/playing-with-neon

Chapters

00:00:00 Intro
00:00:54 Looking into Neon docs
00:02:35 Following the quickstart tutorial from the docs
00:12:32 Reviewing the generated code and exploring the concept of Handle and JS values
00:17:06 Figuring out how to return JavaScript errors
00:27:14 Creating a function to sum 2 numbers
00:33:24 Creating a function to sum the square of an array of numbers
00:38:01 Figuring out how to downcast a generic JsValue to a JsNumber
00:43:06 Completing and testing our implementation
00:45:33 Handling casting errors correctly
00:51:47 Benchmarking against a pure JavaScript implementation
00:55:57 Finding a bug and fixing it
00:59:00 Trying to parallelize our Rust solution using the Rayon crate
01:04:30 Testing with 1 million numbers
01:05:20 Reducing the data passed to Rust by passing only n as the number of items to sum (and not an entire array)
01:14:11 Closing notes

#rust #nodejs #livecoding

If you like this content make sure to follow us on Twitch too: https://twitch.tv/loige




Other Videos By Luciano Mammino (loige)


2023-08-28Fixing Fullstackbulletin.com part 9 - Twitch Live Stream
2023-08-22Luciano Mammino (loige) Live Stream
2023-08-14Fixing Fullstackbulletin.com part 8 - Twitch Live Stream
2023-07-31Fixing Fullstackbulletin.com part 7 - Twitch Live Stream
2023-07-31Fixing Fullstackbulletin.com part 6 - Twitch Live Stream
2023-07-17Fixing Fullstackbulletin.com part 5 - Twitch Live Stream
2023-07-03Fixing Fullstackbulletin.com part 4 - Twitch Live Stream
2023-06-26Fixing Fullstackbulletin.com part 3 - Twitch Live Stream
2023-06-19Fixing Fullstackbulletin.com part 2 - Twitch Live Stream
2023-06-12Fixing Fullstackbulletin.com part 1 - Twitch Live Stream
2023-05-08Creating Node.js libraries with Rust using Neon (Twitch live stream)
2023-04-18Using Zig from Python 😱 (Twitch Live Stream)
2023-04-03🦀 Calling Rust from Python 🐍 with PyO3 (Twitch live stream)
2023-03-22🦀 Exploring Rust crates zip & image (Twitch live stream)
2023-02-27🦀 Learning Rust web servers with Axum & SQLx (Twitch live stream)
2023-02-21Rust crates: async_stream (Twitch live stream 2023-02-20)
2023-02-13Rust crates: custom serde deserializers (Twitch live stream 2023-02-13)
2023-02-09Rust crates: dotenv, reqwest, url, serde, serde-json (Twitch live stream 2023-02-08)
2023-01-23🦀 Learning Rust web servers with Axum (Twitch live stream)
2023-01-09🦀 Learning nom, a Rust parser combinator library (Twitch stream)
2022-11-30Building a Tic Tac Toe game in Solid.js (Twitch Live Stream 2022-11-30)



Tags:
rust
neon
optimization
programming
javascript
rayon
handle
js values
casting errors
benchmarking
summing numbers
sum of squares
array
generic jsvalue
quickstart tutorial
downcasting
bug fixing
million numbers
code
tutorial
learning
live coding
live programming
live stream
learning rust
rust and node
rust and nodejs