On 10/10/2015 15:27, Artella Coding wrote:
Hi, thanks I tried the new FFI and it is definitely faster.
I'm glad it's already showing some improvement. There are some potential optimisations that can be made but I'll leave them for the moment.
Out of curiosity why do the stacks need to be seperate? Would it not be possible to have a ForeignUnsafe for which they share the same stack? Thanks
Having separate stacks is the easiest way of doing it. It wouldn't be a good idea for C code to be run on an ML stack because it could run over the end. ML code checks for stack overflow; C code just runs until it hits a guard page and segfaults. Running ML code on the C stack might be possible. The main problem would be separating out the section(s) of the stack used by ML from that used by C. The GC needs to be able find and possibly update addresses that ML code has pushed to the stack. With callback functions there could be more than one interleaved section of ML stack. The GC could be invoked in a callback or by another thread while a thread is running C.
While I was writing the new FFI code I was thinking of the possibility of streamlining the calling of C with a view to possibly using it in place of the existing RTS call sequence. I think that's for the next phase and probably the next release.
David