Ctypes optimisation

I want to use the Ctypes library but I get a result up to 30 times slower than the conventional method on the function that I tested. Does this seem normal and is it possible to optimize calls with Ctypes?

Are you using stub generation (Cstubs) or dynamic calls (Foreign)?

Of the two, bindings created using stub generation will typically be significantly faster.

1 Like

I am using dynamic calls. I will try stub generation, thanks for the advice.

With Cstubs, my function is as fast as the conventional one without the attribute [@@noalloc], cool!
Is it possible to add the attribute [@@noalloc] with Cstubs?

Most of the internal work to support noalloc is in place, but I’ve been hesitant to enable it in the interface because there are some (probably very rare) edge cases involving C calling back into OCaml where it’s difficult to give guarantees.

There’s an issue open to track support for the feature.