High Performance Apps with JavaScript and Rust

NodeJS is amazing at lots of things, but computationally intensive or low level tasks aren’t among those things. How can you still leverage the ease of use of NodeJS and do things that are computationally expensive like machine learning, or low level things like computations on a GPU? By using Rust and Node together. Rust is a strongly typed cross platform language that is an excellent choice for handing these exact problems. It’s easy to learn and works very well with Node. This talk will teach you Rust syntax and usage from a JS developers perspective, how to write a Rust library to make it callable from NodeJS and finally actually calling the library from NodeJS. After attending this talk you will:
– Have a basic grasp of writing a Rust library
– Know when and how to use Rust
– Understand how to use the foreign function interface to call out from NodeJS
– Execute callbacks to your Node code from your Rust lib.


NodeJS Interactive 2017


Amir Yasin


The Linux Foundation provided Coding Tech with the permission to republish this video.


Original video source: https://www.youtube.com/watch?v=Pfbw4YPrwf4

Additional material for JavaScript learners:
https://amzn.to/2JrUINQ Eloquent JavaScript, 3rd Edition: A Modern Introduction to Programming
https://amzn.to/2HwAMYd Simplifying JavaScript: Writing Modern JavaScript with ES5, ES6, and Beyond
https://amzn.to/2Cq5bmL JavaScript: JavaScript Programming.A Step-by-Step Guide for Absolute Beginners
https://amzn.to/2uhIvAP How JavaScript Works
https://amzn.to/2CwS2bU The Modern JavaScript Collection

Original source

13 thoughts on “High Performance Apps with JavaScript and Rust

  • April 27, 2019 at 17:18

    IMO this FFI-Glue code looks more complex than Neon bindings. Maybe Neon improved since this talk was given. At least neon gives you a nice project layout to develop nodejs/rust side-by-side.

    Another option is to compile rust to wasm and use the WASM blob in NodeJS (which is possible with recent NodeJS versions, 11.x ATM).

    So, counting FFI, Neon and WASM, there are three options to integrate Rust into NodeJS – there's no excuse not to try it šŸ˜‰

  • April 27, 2019 at 17:18

    a couple clarifications:
    Ownership in rust
    a borrow is like a window into the original variable
    mutable just means changable
    immutable borrows can be passed around freely (so long as the windows die before the original does)
    mutable borrows can only be held by one window, until that window goes out of scope (they block immutable borrows to avoid data races)

    Tuples are basically an easy way to return multiple results in a single package. You access it like you would an array

    Vectors are basically what you would normally think of as an array. The difference happens because one of Rust's focuses is on speed. Vectors live on the heap (big, slow memory) and their length can be changed. Arrays live on the stack (small memory that's close to the cpu) and have be a fixed size known at compile time.

    A closure is basically a mini function that fits inside a variable so it can be handed around. (https://doc.rust-lang.org/book/2018-edition/ch13-01-closures.html#refactoring-with-closures-to-store-code)

    Rust has some of the best documentation I've seen in a systems language
    Tutorial/reference (clear, effective, very useful): https://doc.rust-lang.org/book/2018-edition/
    An example page from language wiki (clearly explains every part of the language): https://doc.rust-lang.org/std/collections/index.html

  • April 27, 2019 at 17:18

    tip: when creating a lib project in rust, you can run `cargo run –example foo` where foo lives in the directory `[root]/examples/foo.rs`. This lets you run your application as a program (an example program) but still easy author a lib. This is a better alternative to creating a app if your intent is to create a lib.

  • April 27, 2019 at 17:18

    Rust is a great language if you haven't tried it already. I'm using it to make a 3d game engine that works natively on the browser by compiling down to wasm

Leave a Reply