Taking Elixir to the Metal with Rust
summary
Shows how to replace unsafe C NIFs with Rust using Rustler, including automatic term encoding, panic catching and a JSON example. A naive call using the Rust JSON crate blocks the BEAM for ~1.5s and spikes reductions; reworking the parser into a chunking approach with resource objects yields far better scheduler behavior (reports ~11,300 reductions instead of stalling). Alternatives demonstrated: spawn OS threads to return results asynchronously, or use dirty NIFs/dirty schedulers for long CPU or I/O work.
AI-written summary · about
chapters (23)
- 0:00Start
- 7:34Why write a NIF?
- 10:02ERL_NIF_TERM
- 15:12Getting Started
- 15:31Using master
- 15:58Fetch Dependencies
- 16:30Add Rustler Compiler
- 16:51Configure Rust Crates
- 20:09Simple Approach
- 20:34decoder.rs
- 23:12Let's time our NIF
- 24:02Warning
- 26:37Thread Progress
- 27:40Don't Block the Schedulers!
- 28:41Counting Reductions
- 30:34json.ex
- 31:37NIF Resource Objects
- 33:20decode_iter
- 36:41Chunking Result
- 37:08Rescheduling
- 38:31Threaded NIFS
- 41:00Dirty NIFS
- 42:37Acknowledgements








