<div dir="ltr">Hi Luis,<div><br></div><div>I should have thanked you and your colleagues in my initial email for implementing and maintaining CFFI.</div><div>It is a great library with a super design - personally I like it very much.</div><div><br></div><div>After some thoughts, I agree, that the inlining control is not a fully-baked idea, yet.</div><div>I'll split the patch into INLINE and FTYPE parts.</div><div><br></div><div>You may ask why we have decided to inline (almost) every of the DEFCFUNs?</div><div>CFFI interfaces to C - obviously - and a lot of code in C deals with double-floats and 64-bit integers.</div><div>Without the stubs being inline, every call to C and back produces boxed values, impacting the performance.</div><div><br></div><div><div class="gmail_extra">In the end, one of the reasons why developers interface to C is performance,</div><div class="gmail_extra">so IMHO the CFFI library, which is already great by default, </div><div class="gmail_extra">should allow developers to access every bit of performance that is there.</div></div><div><br></div><div>Regarding the FTYPE declarations - we build our software stacks with different compiler policy settings.</div><div>In developer/test builds the declarations act as run-time assertions.</div><div>In production builds they produce much better optimized code.</div><div>At compile time, we can detect program errors using the type system.</div><div><br></div><div><div class="gmail_extra">The lisp-parameter/value-type generics, introduced here, allow us to declare custom CFFI types</div><div class="gmail_extra">that for example pass like int64 but hold only fixnum values. </div><div class="gmail_extra">Or we can declare a string type that processes as simple-base-string which gives nice optimizations in SBCL.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Also, always declaring FTYPEs on DEFCFUNs is a good thing since the C code</div><div class="gmail_extra">that we interface to is rather static as compared to Lisp code. Thus static function</div><div class="gmail_extra">declarations of C stubs will always be a win.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Cheers,</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_quote">On Mon, Nov 6, 2017 at 10:38 AM, Luís Oliveira <span dir="ltr"><<a href="mailto:luismbo@gmail.com" target="_blank">luismbo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Andrzej,<br>
<span class="m_-1885307285392210306gmail-"><br>
On Wed, Nov 1, 2017 at 10:43 PM, Andrzej Walczak<br>
<<a href="mailto:andrzejwalczak@google.com" target="_blank">andrzejwalczak@google.com</a>> wrote:<br>
> Recently we have migrated one of our largest projects from our home-grown<br>
> foreign-function interface implementation to CFFI.<br>
> The project is almost 1M LOC with almost 1K of foreign-functions.<br>
<br>
</span>Cool! That's interesting to know! </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span class="m_-1885307285392210306gmail-"><br>
<br>
> The attached patch contains a proposal that we would like to share.<br>
> Please, let us know about any modification necessary that would make this<br>
> patch useful for a larger community.<br>
<br>
</span>The idea of automatically inlining DEFCFUNs when SPACE > 2 > DEBUG is<br>
interesting. If we go down that route, we'd better be consistent<br>
across lisps, but I wonder if there's such a thing is possible when<br>
the optimisations vary so much across Lisps. Are CL otimisation<br>
declarations the best way to control the optimisation? I'm skeptical.<br>
I'm also a bit worried about using SBCL internals.<br>
<br>
I'm curious to know the purpose of the declarations. Are you mostly<br>
taking advantage of SBCL's declarations-as-assertions behaviour or are<br>
you looking for some sort of optimisation? Do you have any examples<br>
showing how they help?<br>
<br>
Cheers,<br>
<span class="m_-1885307285392210306gmail-HOEnZb"><font color="#888888"><br>
--<br>
Luís Oliveira<br>
<a href="http://kerno.org/~luis/" rel="noreferrer" target="_blank">http://kerno.org/~luis/</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="m_-1885307285392210306gmail_signature"><div dir="ltr"><div style="font-family:arial;font-size:small"><span style="color:rgb(0,0,0);font-family:Arial;font-size:15px;line-height:17.25px;white-space:pre-wrap">Andrzej Walczak </span></div><div style="font-family:arial;font-size:small"><div style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:Arial;font-size:15px;line-height:17.25px;white-space:pre-wrap">(</span><span style="color:rgb(0,0,0);font-family:Arial;font-size:15px;line-height:17.25px;white-space:pre-wrap"><font color="#0000ff">G</font></span><font color="#ff0000" style="font-family:Arial;font-size:15px;line-height:17.25px;white-space:pre-wrap">o</font><font color="#f1c232" style="font-family:Arial;font-size:15px;line-height:17.25px;white-space:pre-wrap">o</font><font color="#0000ff" style="font-family:Arial;font-size:15px;line-height:17.25px;white-space:pre-wrap">g</font><font color="#38761d" style="font-family:Arial;font-size:15px;line-height:17.25px;white-space:pre-wrap">l</font><font color="#ff0000" style="font-family:Arial;font-size:15px;line-height:17.25px;white-space:pre-wrap">e</font><span style="color:rgb(0,0,0);font-family:Arial;font-size:15px;line-height:17.25px;white-space:pre-wrap">/ITA Software Engineer)</span></div><div><span style="color:rgb(0,0,0);font-family:Arial;font-size:15px;line-height:17.25px;white-space:pre-wrap"><br></span></div></div></div></div>
</div></div></div>