Earlier quoted context omitted.
It’s important to note that while Erlang has protections against user code crashing an Erlang process and recovering, a faulty NIF can take down the entire virtual machine.
Hence why Rustler is of so much interest since it provides more protections against this happening. Discord is a big Erlang + Rustler user.
Zigler: Zig NIFs in Elixir
21–30 of 93 posts
Re: Zigler: Zig NIFs in Elixir
#22Earlier quoted context omitted.
It’s important to note that while Erlang has protections against user code crashing an Erlang process and recovering, a faulty NIF can take down the entire virtual machine.
Hence why Rustler is of so much interest since it provides more protections against this happening. Discord is a big Erlang + Rustler user.
Re: Zigler: Zig NIFs in Elixir
#23Does anyone actually enjoy using these systems that encourage you to embed programming-language X code in programming-language Y heredocs? I always find actually doing that — and then maintaining the results over time — to be quite painful: you don't get syntax highlighting inside the string; you can no longer search your worktree reliably using extension-based filtering; etc. I personally find the workflow much more…
Also, I'm not sure why it's not better documented in Zigler, but you can also write the code in a separate file just fine.
Re: Zigler: Zig NIFs in Elixir
#24For anyone mystified about what a NIF is that doesn't want to go read the docs. The BEAM VM (which is the thing that runs erlang / elixir / gleam / etc) has 3 flavors of functions. - BIFs - Built-in functions, these are written in C and ship with the VM - NIFs - Natively implemented functions, these are written in any language that can speak the NIF ABI that BEAM exposes and allows you to provide a function that look…
It’s important to note that while Erlang has protections against user code crashing an Erlang process and recovering, a faulty NIF can take down the entire virtual machine.
Re: Zigler: Zig NIFs in Elixir
#25I wish zig got more use and attention in the Erlang ecosystem, but rustler seems more popular.
Re: Zigler: Zig NIFs in Elixir
#26For anyone mystified about what a NIF is that doesn't want to go read the docs. The BEAM VM (which is the thing that runs erlang / elixir / gleam / etc) has 3 flavors of functions. - BIFs - Built-in functions, these are written in C and ship with the VM - NIFs - Natively implemented functions, these are written in any language that can speak the NIF ABI that BEAM exposes and allows you to provide a function that look…
It's also important to point out ports, because as you mention, NIFs are a way to integrate external code. But as someone else points out, NIFs can crash the entire BEAM VM. Ports are a safer way to integrate external code because they are just another BEAM process that talks to an external program. If that program crashes, then the port process crashes just like any other BEAM process but it won't crash the entire B…
Re: Zigler: Zig NIFs in Elixir
#27Earlier quoted context omitted.
Hence why Rustler is of so much interest since it provides more protections against this happening. Discord is a big Erlang + Rustler user.
Are they really? Their projects don't look so active
Re: Zigler: Zig NIFs in Elixir
#28Earlier quoted context omitted.
It's also important to point out ports, because as you mention, NIFs are a way to integrate external code. But as someone else points out, NIFs can crash the entire BEAM VM. Ports are a safer way to integrate external code because they are just another BEAM process that talks to an external program. If that program crashes, then the port process crashes just like any other BEAM process but it won't crash the entire B…
And then there are port drivers which are the worst of both worlds! Can crash the BEAM and need much more ceremony than NIF to set up but they’re pretty nice to do in Zig[1] as well [1]: https://github.com/borgoat/er_zig_driver
There's another option and that's setting up an Erlang node in the other language. The Erlang term format is relatively straightforward. But I'm honestly not sure of the benefit of a node versus just using a port.
Re: Zigler: Zig NIFs in Elixir
#29Earlier quoted context omitted.
Are they really? Their projects don't look so active
It’s pretty common in the Elixir ecosystem for these types of libraries to not change very much. Elixir itself doesn’t change too much so these libraries stay solid without needing frequent updates. It doesn’t mean people aren’t using them. Some libraries even put disclaimers that they are actively maintained even if they haven’t seen an update in a long time. It’s something that takes some getting used to for some p…
Something about immutability and the structure of Elixir leads to surprisingly few bugs.
Re: Zigler: Zig NIFs in Elixir
#30I use zig a lot in elixir nif, for things like audio and video processing, it works great. But I do not use zigler as I prefer the code to live in their own codebases. But zigler is really nice and it provides an easy way to do computational heavy tasks in elixir.
Sounds interesting, is it open source? I am interested in seeing how the code layout looks like when mixing Zig and Elixir