<br><br><div class="gmail_quote">On Fri, Nov 19, 2010 at 10:15 AM, Mariano Martinez Peck <span dir="ltr">&lt;<a href="mailto:marianopeck@gmail.com">marianopeck@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><br><div class="gmail_quote"><div class="im">On Wed, Nov 17, 2010 at 1:13 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:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">
<br><br><div class="gmail_quote"><div>On Tue, Nov 16, 2010 at 3:32 PM, Levente Uzonyi <span dir="ltr">&lt;<a href="mailto:leves@elte.hu" target="_blank">leves@elte.hu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">


On Tue, 16 Nov 2010, Juan Vuletich wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">
Hi Levente,<br>
<br>
Levente Uzonyi wrote:<br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">
Hi,<br>
<br>
I&#39;m mostly ready with this cleanup, only a few methods left in the image that use #== for integer comparison. Some of them must use #==, others may be changed, but I wasn&#39;t sure if the code will work if it&#39;s changed or not. If you&#39;d like to check these methods, then evaluate the following in a workspace:<br>



<br>
... code here...<br>
<br>
Cheers,<br>
Levente<br>
</blockquote>
<br>
Thanks for the snippet! It is now a method in Cuis. I also checked a bit on trunk. In all senders of #nextObject you can apply the pattern in #allObjectsDo:. Instead of assuming == 0 for last #nextObject, it assumes that Object new will go at the end. If that ever changed, a few places would need fixing...<br>



</blockquote>
<br>
I&#39;m not sure if it&#39;s ok to use that pattern in ImageSegment. Even if it&#39;s ok, the code is so messy, that it seems to be hard to apply the pattern without breaking the code.<br>
<br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">
<br>
As an experiment, in #allObjectsDo: I tried to remove the Object new stuff and replace with &#39;[ 0 = object and: [ object isMemberOf: SmallInteger ]] whileFalse: &#39;, but my test became extremely slow. I suspect #= is sending the message even if it has its own bytecode... So, the only method that remains with the &#39;0 ==&#39; pattern in Cuis is #critical:ifLocked: , as I&#39;m not sure if we can clean it.<br>



</blockquote>
<br>
#= is a special selector, so I&#39;m sure it won&#39;t send a message if it doesn&#39;t have to.</blockquote><div><br></div></div><div>Um, on Cog it sends a message if the method containing the #= has been jitted.  </div>

</div></blockquote></div><div><br>Hi Eliot. I have just read the whole thread, but I wanted to ask you something about this line. Did I understand correct??  If #= has already been jitted, then Gog doesn&#39;t use the 
short-circuit sends (#bytecodePrimEqual) but it does a normal send (a primitive in this case)?  So...suppose I change SmallInteger &gt;&gt; #=   and I put a halt, then if will be halted (and broke everything, of course) once that method was jitted ?<br>
</div></div></blockquote><div><br></div><div>Yes, that&#39;s right; since in Cog jitted code #= is always sent if you put a breakpoint in SmallInteger&gt;#= execution will hit the break-point, unlike in the interpreter.  </div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote"><div>
And I guess the same happens with all special selectors.<br><br>Thanks<br><font color="#888888"><br>Mariano<br><br> </font></div><div><div></div><div class="h5"><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">

<div class="gmail_quote"><div>But the issue is /not/ whether there is a send or not.  The issue is what the behaviour of the primitive code is.  In the interpreter #= will short-circuit (avoid the send) if both the receiver and the argument are either a SmallInteger or a Float.  In the JIT the primitive will not fail if the receiver and argument are both SmallIntegers or Floats or if the receiver is a Float and the argument is an Integer, but will fail if the receiver is a SmallInteger and the argument is a Float.</div>


<div> </div><div>In general the VM is free to fail for non-matching numeric types (this is historical, derived from the blue book) so I don&#39;t feel Cog is at fault here.  Certainly it is not answering incorrect results; it is simply taking more sends to produce the result in some circumstances. I think in cases like this (where you&#39;re enumerating over all objects) using #== is a wiser choice.</div>


<div><br></div><div>HTH</div><div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex"> It&#39;s possible that #= is a bit slower than #== because it has to do some extra checks, but the difference is probably neglible. Here&#39;s a benchmark:<br>



<br>
| offset equality identity |<br>
Smalltalk garbageCollect.<br>
offset := [ 1 to: 1000000 do: [ :i | ] ] timeToRun.<br>
equality := [ :x | [ 1 to: 1000000 do: [ :i | 0 = x ] ] timeToRun ].<br>
identity := [ :x | [ 1 to: 1000000 do: [ :i | 0 == x ] ] timeToRun ].<br>
{ 0. 1. SmallInteger maxVal. SmallInteger maxVal + 1. nil. Object new. 0.0. Array new. 1/2 } collect: [ :each |<br>
        each -&gt; ({<br>
                equality value: each.<br>
                identity value: each.<br>
                equality value: each.<br>
                identity value: each.<br>
                equality value: each.<br>
                identity value: each } - offset) ].<br>
<br>
And my results on CogVM:<br>
<br>
{<br>
        0-&gt;#(3 2 3 1 3 2).<br>
        1-&gt;#(2 4 3 0 3 4).<br>
        1073741823-&gt;#(3 3 2 1 3 5).<br>
        1073741824-&gt;#(221 4 223 1 223 4).<br>
        nil-&gt;#(14 4 14 0 15 4).<br>
        an Object-&gt;#(14 5 13 1 14 4).<br>
        0.0-&gt;#(622 5 623 2 624 4).<br>
        #()-&gt;#(16 5 14 1 16 4).<br>
        (1/2)-&gt;#(260 4 259 1 258 5)<br>
}<br></blockquote><div><br></div></div><div>I&#39;d do many more iterations.  I wouldn&#39;t put any faith any millisecond numbers that are less than 3 digits (100 ms).</div><div><div> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">



<br>
So the cause of the slowdown in your #allObjectsDo: implementation is that #= is only fast if both the receiver and the argument are SmallIntegers, otherwise there will be message sends.<br>
<br>
Another way to implement #allObjectsDo: without the marker object is to replace the loop condition with: object class == SmallInteger. It&#39;s actually the same as your implementation without the #= check. #isMemberOf: is optimized to non-real sends. This is as fast as the current implementation on my pc.<br>



<br>
<br>
Levente<br>
<br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">
<br>
Cheers,<br>
Juan Vuletich<br>
<br>
<br>
</blockquote>
<br>
</blockquote></div></div><br>
<br><br>
<br></blockquote></div></div></div><br>
<br><br>
<br></blockquote></div><br>