elixir-explorer / explorer

Series (one-dimensional) and dataframes (two-dimensional) for fast and elegant data exploration in Elixir
https://hexdocs.pm/explorer
MIT License
1.12k stars 123 forks source link

Implement message-on-gc functionality in Rust #934

Closed filmor closed 4 months ago

filmor commented 4 months ago

@cocoa-xu, @josevalim FYI

I'm not happy with the necessity to use two mutexes here and will see, whether SavedTerm can be improved.

josevalim commented 4 months ago

Thank you @filmor! Do you think the change is worth it, given the C version does not have to deal with mutexes? Or it does have to deal with them, it is just that we cannot see them? 🤔

josevalim commented 4 months ago

Btw, this was closed automatically by GitHub because I merged the other PR (and the branch was automatically removed). Please do submit it against main (and sorry for the inconvenience!).

filmor commented 4 months ago

I'll resubmit. It's not quite there, yet, anyhow because enif_send is so ... weirdly specific about its env argument.

The C variant doesn't have to deal with mutexes because it is inherently unsafe. This is irrelevant for this particular resource type, as it is never actually "used" and we can trust the destructor to be only called exactly once. I can do the same in Rust by adding an unsafe impl Sync for LocalMessage {}.

The main reason I am looking into this is that I'd like "all" patterns to be implementable directly in Rust, everything that requires dropping down to C (or even unsafe) is a bug to me.