Erlang / Erlang Basics Interview questions
What is a NIF (Native Implemented Function)?
A NIF is a function implemented in C (or another native language) and loaded directly into the BEAM, callable from Erlang exactly like an ordinary function. It's used when pure Erlang is too slow for a specific hot path, such as heavy numeric or cryptographic work.
-module(math_nif). -export([fast_add/2]). -on_load(init/0). init() -> erlang:load_nif("./math_nif", 0). fast_add(_A, _B) -> erlang:nif_error(not_loaded).
The catch: a NIF runs inside the scheduler thread, not as a separate lightweight process, so a slow or crashing NIF can stall that scheduler or even bring down the entire node — it doesn't get the isolation a regular Erlang process gets. Because of that risk, NIFs are meant for short, fast operations, with long-running native work usually handed off to a port or a dirty scheduler instead.
More Related questions...