<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">That would radically increase the number of collisions from the hash function. I don’t think that is a good idea. *Especially* when we are talking about a hash function that will be used for dictionaries. When you test the performance of a hash function you should also test it’s properties w.r.t. to hashed collections (Andrés Valloud explains that nicely in “Hashing in Smalltalk”).<div class=""><br class=""></div><div class="">Cheers,</div><div class="">Max<br class=""><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 13 Apr 2017, at 23:19, Clément Bera <<a href="mailto:bera.clement@gmail.com" class="">bera.clement@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><span style="font-size:12.8px" class="">Hi all,</span><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">I am trying to investigate performance overhead in benchmarks to improve the VM performance. In a benchmark strings are used as dictionary keys, which seems to be an OK pattern to me that may be actually used in real code from time to time. Something stroke me: <u class="">the hash function of a string is actually iterating over the whole string. </u><br clear="all" class=""><div class=""><br class=""></div><div class="">As a result, I get something like this:</div><div class=""><br class=""></div><div class="">#(</div><div class="">'String size: 0, Hash function performance: 17,817,776 per second' </div><div class="">'String size: 1, Hash function performance: 15,395,388 per second' </div><div class="">'String size: 3, Hash function performance: 14,853,109 per second' </div><div class="">'String size: 4, Hash function performance: 15,151,954 per second' </div><div class="">'String size: 5, Hash function performance: 14,139,881 per second' </div><div class="">'String size: 10, Hash function performance: 11,545,749 per second' </div><div class="">'String size: 65, Hash function performance: 3,431,067 per second' </div><div class="">'String size: 130, Hash function performance: 1,879,047 per second' </div><div class="">'String size: 520, Hash function performance: 511,934 per second'</div><div class="">)<br class=""></div><div class=""><br class=""></div><div class="">This means that if a hash of a 1MB String is computed it takes a hell of a time. </div><div class=""><br class=""></div><div class="">I wonder why we don't compute the string hash from a small number of inner characters taken randomly but deterministically from the String. From example, for all strings longer than 5 characters, one could pick only 5 characters in the String to compute its hash. The hash function is this way decent enough and the performance does not drop for large strings.</div><div class=""><br class=""></div><div class="">One implementation could be to replace:</div><div class=""><font face="monospace, monospace" class="">1 to: stringSize do: [:pos |</font></div><div class="">by:</div><div class=""><font face="monospace, monospace" class="">1 to: stringSize by: stringSize // 5 do: [:pos |</font></div><div class="">in:</div><div class=""><font face="monospace, monospace" class="">ByteString>>stringHash: aString initialHash: speciesHash</font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="arial, helvetica, sans-serif" class="">Then we need to rehash the whole image.</font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class="">What do you think ? Is there a hash expert around that can confirm this is a good idea ? </div></div>
</div>
</div></blockquote></div><br class=""></div></div></div></body></html>