cigrainger
Hey everybody! I’m delving into Rustler to enable some work on data frames in Elixir backed by polars. I’m feeling pretty confident in the mental model of using a nif resource and delegating to native functions for much of the API. One place I’m struggling to get my head around is arbitrary elixir functions on data in the nif resource. The python bindings for polars enable passing lambdas across that are then applied on the polars dataframe (see here). Does Rustler enable something or is there a preferred interop path for this sort of thing? It feels like a pretty heavy approach to serialise, apply, then deserialise back.
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #ai
- #graphql
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex











Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
josevalim
As far as I know it is not possible to call Elixir/Erlang functions from C/Rust code.
cigrainger
Thanks José! I suppose I’ll cross that bridge when I get there then. Won’t hurt to start with serialise/apply/deserialise. I’m not sure if pyo3’s approach of embedding a Python interpreter in the binary is particularly reasonable anyway. I may be imagining bottlenecks in copying before I’ve proved the problem anyway.
amnu3387
Not sure how helpful this is, but if you can link C libs and you want to serialise stuff, there’s Erlang Interface / docs
You can then from C encode terms:
Which encodes a tuple with five elements,
{long/unsigned, int, int, long/u, int}.And from the Elixir/Erlang side call
binary_to_term(Rem), which decodes it into a normal tuple.tessi
Hi,
I am pretty sure it’s possible to call from a NIF into elixir because I’m doing just that in wasmex
Someone asked about how I do that in a GitHub issue where I explained the why’s and how’s in a little more detail:
https://github.com/tessi/wasmex/issues/256#issuecomment-848339952
Feel free to ask away if there is any questions
akash-akya
Hi @tessi, thanks for taking time to write this approach. I also played around same idea in the past (in C though).
Just want to highlight the risks involved if someone is considering
I think there were few more but not able to recall at the moment.
Another reference: [erlang-questions] Calling Erlang functions from NIFs
tessi
Thanks @akash-akya
your points are very valid. The whole thing is a big dance for just calling into Elixir. But it’s possible. I think in Rust, the thread handling part is a little more safe, but still deadlocks are possible. (we could build in timeouts, though, so that things eventually return).
And yes, it’s not super efficient. It could be much more efficient and more easy to build if we settle for async calls (message sends) only.
cigrainger
Thanks! Wow, @tessi that is very impressive work. Your explanation of the ResourceArc is really helpful for me and I’d love to see clearer explanations like that in the official documentation. That’s really where I’m hurting the most. Definitely simplified in 0.22.0-rc though.
Probably not terribly useful for what I’m working on to call into Elixir that way, but seeing how you did it is extremely enlightening.
ityonemo
Wow that’s super impressive. It’s giving me ideas though, I think there might be a clever and safe way of doing this in zigler by yielding first, and storing the frame, then resuming once the result term has come back. If the owning process is killed, the resource can be freed and the yield will exit, triggering cleanup of allocated memory, etc.