<div dir="ltr"><div><br></div><br><div class="gmail_quote">On Mon, Jun 22, 2015 at 9:35 AM, David T. Lewis <span dir="ltr">&lt;<a href="mailto:lewis@mail.msen.com" target="_blank" style="color:rgb(17,85,204)">lewis@mail.msen.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>That sounds right to me too. But it would be a worthwhile experiment to<br>set up a test to confirm it. Maybe take one or more methods that call<br>numbered primitives, and recode them to call the primitives by name. Then<br>measure and see if anything got slower.<br><br>Dave<br><div class="HOEnZb"></div></blockquote></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 22, 2015 at 10:40 AM, Eliot Miranda <span dir="ltr">&lt;<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Esteban,<div><br></div><div>    you can set up a test using the LargeInteger comparison primitives.  They&#39;re both named and numberd.  e.g.</div><div><br></div><div>23 primitiveLessThanLargeIntegers<br></div><div><br></div><div>So you can write e.g.</div><div><br></div><div><div>LargePositiveInteger&gt;&gt;#&lt; anInteger </div><div><span style="white-space:pre-wrap">        </span>&quot;Primitive. Compare the receiver with the argument and answer true if</div><div><span style="white-space:pre-wrap">        </span>the receiver is less than the argument. Otherwise answer false. Fail if the</div><div><span style="white-space:pre-wrap">        </span>argument is not a SmallInteger or a LargePositiveInteger less than 2-to-the-30th (1073741824).</div><div><span style="white-space:pre-wrap">        </span>Optional. See Object documentation whatIsAPrimitive.&quot;</div><div><br></div><div><span style="white-space:pre-wrap">        </span>&lt;primitive: 23&gt;</div><div><span style="white-space:pre-wrap">        </span>^super &lt; anInteger</div></div><div><br></div><div>as</div><div><br></div><div><div>numberedLessThan: anInteger </div><div><span style="white-space:pre-wrap">        </span>&quot;Primitive. Compare the receiver with the argument and answer true if</div><div><span style="white-space:pre-wrap">        </span>the receiver is less than the argument. Otherwise answer false. Fail if the</div><div><span style="white-space:pre-wrap">        </span>argument is not a SmallInteger or a LargePositiveInteger less than 2-to-the-30th (1073741824).</div><div><span style="white-space:pre-wrap">        </span>Optional. See Object documentation whatIsAPrimitive.&quot;</div><div><br></div><div><span style="white-space:pre-wrap">        </span>&lt;primitive: 23&gt;</div><div><span style="white-space:pre-wrap">        </span>^super &lt; anInteger</div></div><div><br></div><div><div><br></div><div><div>namedLessThan: anInteger </div><div><span style="white-space:pre-wrap">        </span>&quot;Primitive. Compare the receiver with the argument and answer true if</div><div><span style="white-space:pre-wrap">        </span>the receiver is less than the argument. Otherwise answer false. Fail if the</div><div><span style="white-space:pre-wrap">        </span>argument is not a SmallInteger or a LargePositiveInteger less than 2-to-the-30th (1073741824).</div><div><span style="white-space:pre-wrap">        </span>Optional. See Object documentation whatIsAPrimitive.&quot;</div><div><br></div><div><span style="white-space:pre-wrap">        </span>&lt;primitive: &#39;primitiveLessThanLargeIntegers&#39;&gt;</div><div><span style="white-space:pre-wrap">        </span>^super &lt; anInteger</div></div></div><div><br></div><div>and test it with two suitable large integers.  Will you report back?  I&#39;d like to know the answer.  Named primitive invocation should be slightly slower.  As Clément says, a return different address is written to the stack, overwriting the primitive code, but that return path is essentially the same as for numbered primtiives.  So I expect that there will be almost no measurable difference.</div></div></blockquote><div><br></div><div>Wow, it is indeed a significant difference.  Substituting the return address must invoke all sorts of cost in an x86 cpu.  Here are 2 x 5 runs</div><div><br></div><div><br></div><div>| i | i := SmallInteger maxVal + 1.</div><div>(1 to: 6) collect: [:j| {[1 to: 10000000 do: [:k| i numberedLessThan: i]] timeToRun. [1 to: 10000000 do: [:k| i namedLessThan: i]] timeToRun}]</div><div><br></div><div>#(#(191 283) #(211 375) #(281 405) #(300 411) #(281 421) #(296 409)) #(#(186 267) #(201 273) #(210 364) #(294 410) #(313 400) #(292 405))</div><div><br></div><div>So the overhead is of the order of (100ms / 10,000,000) per call.  e.g. around 10ns per named primitive call.  Interesting :-)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>This is all to do with callbacks.  Numbered primitives are assumed never to callback (so far that&#39;s a valid assumption).  But named primitives (such as an FFI call) may indeed callback and hence, by the time the primitive finally returns the code zone may have been compacted and the original method containing the callout may have moved.  So the VM can&#39;t simply return to a primitive that may have called back, and then have that primitive&#39;s code return form the primitive, because that codee may have moved.  The solution is to provide a piece of code at a fixed address that returns from a named primitive call, and have the return sequence run that code.</div></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Mon, Jun 22, 2015 at 5:13 AM, Esteban Lorenzano <span dir="ltr">&lt;<a href="mailto:estebanlm@gmail.com" target="_blank">estebanlm@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Hi,<br>
<br>
Any idea how slower is? I mean, any measure/estimation/something around?<br>
<br>
cheers,<br>
Esteban<br>
<br>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div>best,<div>Eliot</div></div>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">best,<div>Eliot</div></div>
</div></div>