tizoc / ocaml-interop

OCaml<->Rust FFI with an emphasis on safety.
MIT License
134 stars 21 forks source link

Add global and generational roots #25

Open g2p opened 3 years ago

g2p commented 3 years ago

This requires ocaml-sys 0.19.1, which exposes the required runtime API.

tizoc commented 3 years ago

About this one, my intention is to introduce "BoxRoots" in the next version of ocaml-interop, which will serve as a faster replacement to global roots (and probably will also replace local roots). I think this new API is something you may find useful if you are using a high amount of global roots.

Work (for the generic implementation that is independent from ocaml-interop) is being done here right now in case you are interested in knowing more about it: https://gitlab.com/ocaml-rust/ocaml-boxroot/

g2p commented 3 years ago

Thanks for the pointer to boxroots, I had no idea you could hook into the GC like that. I don't have so many global roots, but I imagine switching locals might improve performance.

tizoc commented 3 years ago

@g2p boxroots have been merged into master. I plan to do a new release (0.6.0) today, when I will go through your PRs.

Does this one still make sense? Global roots can do one thing that Boxroots cannot, and that is registering an arbitrary address as a root. But such functionality is not often needed, and for everything else Boxroots beat global roots.

Do you think this PR is still relevant?

g2p commented 3 years ago

Personally I would prefer to still have functionality that works without boxroots, because the deep integration of boxroots support with the OCaml runtime in the current implementation makes using Rust as an extension language for OCaml libraries (my use case, and one ocaml-rs targets) a bit visible (need for setup and teardown, likely interactions with Mirage and ocaml-freestanding) and not seamless.

Though that discussion is about scope, and goes beyond this PR.

tizoc commented 3 years ago

@g2p setup and teardown requirements are temporary, and will be removed from future releases (irrespectively of if boxroots get integrated into OCaml or not).

tizoc commented 3 years ago

Btw, here is the OCaml RFC for boxroots in case you are interested in following the discussion https://github.com/ocaml/RFCs/pull/22

g2p commented 3 years ago

Okay; pardon the worry. I can table this for now, and wish the RFC well.