<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jan 18, 2012, at 11:05 11PM, Mariano Martinez Peck wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><br><br><div class="gmail_quote">On Wed, Jan 18, 2012 at 10:02 PM, Eliot Miranda <span dir="ltr">&lt;<a href="mailto:eliot.miranda@gmail.com">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">
&nbsp;<br><br><br><div class="gmail_quote">On Wed, Jan 18, 2012 at 12:54 PM, Henrik Johansen <span dir="ltr">&lt;<a href="mailto:henrik.s.johansen@veloxit.no" target="_blank">henrik.s.johansen@veloxit.no</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
&nbsp;<br><div style="word-wrap:break-word"><br><div><div>On Jan 18, 2012, at 8:02 50PM, Eliot Miranda wrote:</div><br><blockquote type="cite"><br><br><div class="gmail_quote">On Wed, Jan 18, 2012 at 2:25 AM, Henrik Johansen <span dir="ltr">&lt;<a href="mailto:henrik.s.johansen@veloxit.no" target="_blank">henrik.s.johansen@veloxit.no</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I really don't see what good could come of it being available in general…<br></blockquote><div><br></div><div>I can think of one good use, which my file tried to illustrate. &nbsp;If Symbol instances identity hashes were derived from their string hash then they would be hashed the same in all images. &nbsp;One can take advantage of this in e.g. method dictionary layout and hence binary class loading. &nbsp;This happens in two steps.</div>


<div><br></div><div>With modern machines, where linear search through a dictionary is fast, and with a JIT with inline cacheing (and even an interpreter with a large method lookup cache), where method dictionaries are not looked at much, one can save a significant amount of space by making method dictionaries flat pair-wise arrays of selector, method. &nbsp;Most method dictionaries are small and linear search is faster than fetching the Symbol's identity hash and doing a hash probe. &nbsp;By ordering method dictionaries&nbsp;&nbsp;by selector identityHash, very large method dictionaries such as Object's are indexed using binary search. &nbsp;We saved about 8% of the image size in VisualWorks by moving to this representation (one saves on eliminating the nils in the selector vector and the value vector, and in eliminating the value vector/method array, hence saving its header space; you still need the space for the method). &nbsp;[The savings in Squeak look to be much less; I just found that he same overhead in the 4.3 trunk image is only&nbsp;~ 1.7%].</div>


<div><br></div><div>Now, if in addition selector identityHashes are deterministic, derived from their string hash, then one does not need to rehash/reorder a method dictionary when loading it from a binary stream (e.g. Fuel), which is again a win.</div>


<div><br></div><div>Now, I'm not suggesting we do either of these things now, but making Symbol identity hashes deterministic, derived from their string hash, can enable significant optimisation further down the road.</div>


</div></blockquote><br></div><div>And I wasn't suggesting it is a bad thing to use in all cases, but rather protesting having a method in the image screaming "use me if you need to change identityHash for whatever reason!" There's just no good general comment to put there on when it might be a good idea, and "Don't use this unless you know what you're doing!" never seems to stop anyone (well, speaking on my own behalf at least…)</div>

<div><br></div><div>I'd rather see usage defined on a case-by-case basis, where you can more explicitly comment why using it in this particular case is a good idea, like you wrote above, and what Mariano mentioned for proxies.</div>

<div><br></div><div>So rather than:&nbsp;</div><div><br></div><div>Object setIdentityHashTo: aNumber</div><div><span style="white-space:pre-wrap">        </span>&lt;primitive: 161&gt;</div><div><span style="white-space:pre-wrap">        </span></div>

<div><br></div><div>you have:</div><div><br></div><div>Symbol &gt;&gt; initialize</div><div><span style="white-space:pre-wrap">        </span>self deriveIdentityHashFrom: self hash</div><div><br></div><div>Symbol &gt;&gt;&nbsp;deriveIdentityHashFrom: aNumber</div>

<div><span style="white-space:pre-wrap">        </span>"This should ONLY be called as part of object initialization!"</div><div><span style="white-space:pre-wrap">        </span>"Symbols benefit from not using the default identityHash by *insert Eliots explanation here*"</div>

<div><br></div><div>and similar for Mariano's Proxy class.</div><div><br></div><div>Cheers,</div><div>Henry</div></div></blockquote><div><br></div><div>Good idea!&nbsp;</div></div><br></blockquote><div><br>Wait...I am slower than Eliot ;)<br>
so...deriveIdentityHashFrom:&nbsp; should be with the primitive call, right?&nbsp; otherwise I am lost.<br><br><div>Symbol &gt;&gt;&nbsp;deriveIdentityHashFrom: aNumber</div>
<div><span style="white-space:pre-wrap">        </span>"This should ONLY be called as part of object initialization!"</div><div><span style="white-space:pre-wrap">        </span>"Symbols benefit from not using the default identityHash by *insert Eliots explanation here*"</div>

<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;primitive: 161&gt;&nbsp;</div></div></div></blockquote>Yes, exactly like it is in his change set example which I'd missed :/</div><div><br></div><div>Cheers,</div><div>Henry</div></body></html>