<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="">Hi François,<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 9, 2017, at 11:46 PM, Francois Fayard via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div 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=""><div class=""><br class=""></div><div class=""></div><blockquote type="cite" class=""><div class="">On Jan 10, 2017, at 2:31 AM, Chris Lattner <<a href="mailto:sabre@nondot.org" class="">sabre@nondot.org</a>> wrote:</div><div class=""><br class="">As others have pointed out, 37 does have some nice properties (by being prime), but we’ve also had it from the very early days. I wouldn’t say that it has been extremely well considered at all.<br class=""><br class="">-Chris<br class=""></div></blockquote><div class=""><br class=""></div>Thanks for your reply. But I am not sure to understand the last sentence. Does it mean that this hash function has been criticized before? Do you also think that it can be improved?<div class=""><br class=""></div><div class="">I am sorry to insist on that, but I don’t see any advantage of using hash(k) = c * k with c being a primer number. What is important is choosing c such that gcd(c, m) = 1 for any size m of the hash table. This is the case for c = 1. As a consequence, I don’t see any benefit in using c = 37 over c = 1. Moreover, all those hash functions are badly considered for a reason : they behave very poorly when the keys are of the form d * k0 + k1.</div><div class=""><br class=""></div><div class="">I really think that this hash function could be improved. But to know if it's worth it, I would like to know if having a better hash for integer types would benefit LLVM.</div></div></div></blockquote><div><br class=""></div></div>Some tests I can suggest is to replace the hash function with your favorite and:</div><div class=""><br class=""></div><div class="">1) Test the impact on the performance (is an LTO link of clang faster? Is `clang -O0` getting faster?), because ultimately I believe real-world impact is the best way to get a change in.</div><div class="">2) Instrument the DenseMap accessors with counters and measure impact on the number of collisions when changing the hash function.</div><div class=""><br class=""></div><div class="">— </div><div class="">Mehdi</div><div class=""><br class=""></div></body></html>