<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.28.1">
</HEAD>
<BODY>
<BR>
<BLOCKQUOTE TYPE=CITE>
<PRE>
While alloca is not as cheap as, say, C's alloca, you should find that 
it is much quicker than C's malloc.  I'm sure there's room for 
optimisation if it's critical for you.  There may well be low-hanging 
fruit: take a look at the Core for alloca.
</PRE>
</BLOCKQUOTE>
Thank you, Simon.<BR>
<BR>
Indeed, there is a low-hanging fruit.<BR>
<BR>
&quot;alloca&quot;'s type is &quot;Storable a =&gt; (Ptr a -&gt; IO b) -&gt; IO b&quot; and it is not inlined even though the function is small. And calls to functions of such signature are expensive (I suppose that's because of look-up into typeclass dictionary). However, when I added an &quot;INLINE&quot; pragma for the function into Foreign.Marshal.Alloc the time of execution dropped from 40 to 20 nanoseconds. I guess the same effect will take place if other similar functions get marked with &quot;INLINE&quot;.<BR>
<BR>
Is there a reason why we do not want small FFI-related functions with typeclass arguments be marked with &quot;INLINE&quot; pragma and gain a performance improvement?<BR>
The only reason that comes to my mind is the size of code, but actually the resulting code looks very small and neat.<BR>
<BR>
With kind regards,<BR>
Denys Rtveliashvili
</BODY>
</HTML>