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
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










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.