Erlang Native Implemented Function
NIFs were introduced in Erlang/OTP R13B03 as an experimental feature. It is a simpler and more efficient way of calling C-code than using port drivers. NIFs are most suitable for synchronous functions, that do some relatively short calculations without side effects and return the result. Although in recent versions become a mature feature with wide adoption. Modern NIF API allows performing wide range of task including spawning threads, performing IO operations and perform lengthy work using experimental (R18-19) dirty schedulers. NIFs became preferred choice for integrating foreign code in Erlang/OTP distribution (binary, maps, ssl).
A NIF is a function that is implemented in C instead of Erlang. NIFs appear as any other functions to the callers. They belong to a module and are called like any other Erlang functions. The NIFs of a module are compiled and linked into a dynamic loadable, shared library (SO in UNIX, DLL in Windows). The NIF library must be loaded at runtime by the Erlang code of the module.
As a NIF library is dynamically linked into the emulator process, this is the fastest way of calling C-code from Erlang (alongside port drivers). Calling NIFs requires no context switches. But it is also the least safe because a crash in a NIF brings the emulator down too.