Hello,<br>When I was using C code from Python, the overhead put on calling C code by Python was significant.<br>To simplify, say I have on C-side two procedures f and g, I do all the stuff to call them in a row from Python, well I'm better off factorizing: adding on C side a wrapper h procedure that calls them both, and then call h from Python, because then I will have half as much overhead:<br>
<br>Instead of SwitchToC -> call f -> SwitchToPython -> SwitchToC -> call g -> SwitchToPython,<br>the factorization leads to SwitchToC -> call f -> call g -> SwitchToPython,<br>which gives the same result yet is different performance-wise because each switching has a cost.<br>
<br>This is painful, because if another time I have to call f and j (another function), then I have to make another wrapper.<br><br>In Haskell world, now, given that my functions f and g would have been imported using <b>unsafe</b>:<br>
<br>foreign import unsafe "f" f :: Thing -> Foo -> IO ()<br>foreign import unsafe "g" g :: Stuff -> Bar -> IO ()<br>foreign import unsafe "h" h :: Thing -> Foo -> Stuff -> Bar -> IO ()<br>
<br>Are<br>doStuff = f x y >> g z w<br>and<br>doStuff = h x y z w<br>equivalent, or is there an overhead (e.g. due to IO monad, or due to the way the FFI does the calls) when compiled (if need be with optimizations) with GHC? <br>