Hi folks, I’m a tad surprised to find no debate on using port drivers vs NIFs. Perhaps I am using the wrong search words; if so, I’d much appreciate pointers.
Can you please comment on the following?
-
As far as I understand, port drivers and NIFs are both in-process, so a crash can kill both. Yes?
-
I don’t understand why the Erlang community makes such a fuss about the dangers of linked in native code, esp now that there are dirty schedulers. Yes, the process can crash, but so what? 99% of Erlang code out there isn’t running in an MRI or space shuttle. All python extensions are natively linked, and they get on just fine; crashes rarely happen, and when they do, it is fine to restart it manually or some external infrastructure. That’s what Amazon and Whatsapp do anyway. There is no need to be so skittish. Comments?
-
Port drivers are like python’s ctypes. They allow you to do all the wrapping of C data types in Erlang space, and then you can directly call a dynamically loaded function. Is this understanding correct?
-
Port drivers are always asynchronous. NIFS are synchronous by default. Yes?
-
Is there a reason why one should prefer NIFs over port drivers or vice-versa? Can the latter’s functions be selectively scheduled on a dirty scheduler? One reason I can think of is that with port drivers, I cannot call C++ code (because I don’t want to deal with mangled names).
Any tips/tricks/advice/pushback most appreciated. Thank you much.