29 ms·
There are two ways to call into C code from OCaml depending on whether the C code needs to allocate on the OCaml heap or not. If not (the so-called "noalloc" m
by rwmj 8y ago
There are two ways to call into C code from OCaml depending on whether the C code needs to allocate on the OCaml heap or not. If not (the so-called "noalloc" method) then it's just a call instruction. Otherwise it goes through a trampoline which IIRC uses a computed branch which probably kills branch prediction.
One other problem is that you cannot inline C into OCaml functions (which is generally true when mixing languages) so there's always some overhead even in the noalloc case, although it will be fairly small on modern CPUs.
Edit: https://camltastic.blogspot.com/2008/08/tip-calling-c-functions-directly-with.html https://camltastic.blogspot.com/2008/08/tip-calling-c-functi...