Back in the day there were various attempts to write a JIT compiler for OCaml. Amongst other things this promises a much faster top level.
There was the ocaml-jit project but that was x86 and I have since moved to x64 and then Aarch64 (M1). Then, 14 years ago, there was the ocamljit2 project that targeted OCaml v3.12 and touted huge benefits .
What is the status of JIT compilation for OCaml today?
gasche
February 21, 2022, 5:26pm
#2
If I remember correctly, ocamljit2 was not maintained.
Currently there is an in-progress effort to revive natdynlink
and make it easier for native applications to programmatically compile code fragments and link them into the currently running program: Fast native toplevel using JIT by jeremiedimino · Pull Request #15 · ocaml/RFCs · GitHub .
3 Likes
That’s great, thanks!
I was actually banking on being able to use natdynlink in a future project. Good to know it isn’t working!
dra27
February 23, 2022, 10:18am
#4
natdynlink is working - it’s more that ocamlnat
(the native toplevel for OCaml) has been receiving some considerable attention.
1 Like
copy
February 24, 2022, 2:35pm
#5
Just a small thing I’d like to add: I extended @dra27 ’s ocaml-jit to support dynlinking directly from OCaml source without a toplevel: Allow dynlink/eval usage by copy · Pull Request #5 · NathanReb/ocaml-jit · GitHub The patch is pretty small, mostly moving usages of the toplevel api out of the library and exposing functions to add symbols that can be used by the evaluated code. An eval example looks like this: ocaml-jit/eval.ml at 57ef5c906681562186565ff28eeb49eb8e05527e · NathanReb/ocaml-jit · GitHub
I think it’s a much lighter alternative to ocaml_plugin , which embeds the OCaml compiler in a tar archive. Feedback is welcome.
1 Like
Brilliant. That’s actually much closer to what I was hoping for. Thanks!