Ctypes optimisation

#1

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?

#2

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
#3

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

#4

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?

#5

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.