<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - IdentifierRepHash has a mismatch between hash() and equal()"
   href="https://bugs.webkit.org/show_bug.cgi?id=150137">150137</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>IdentifierRepHash has a mismatch between hash() and equal()
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>WebKit
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>WebKit Nightly Build
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>Normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P2
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>JavaScriptCore
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>webkit-unassigned&#64;lists.webkit.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>fpizlo&#64;apple.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>IdentifierRepHash inherits equal() from PtrHash, so it defines equality as pointer equality.  But it implements hash() by calling the StringImpl's hash method.

This seems either incorrect or inefficient.

The hash() method will return a hash value based on the string's value, not the string's identity.  So, non-identical string might end up having the same value and so the same hash.  Also, that hash takes more effort to compute than the normal PtrHash.

Quite likely, the PtrHash::hash method would be most efficient, since it doesn't require loading from the pointer.  Loads are usually the more expensive things.

Also, this means that we cannot have a HashMap with IdnetifierRepHash that doesn't ref its strings and outlives some of the strings that are in it.  This seems dirty, but it might actually be profitable in some cases, like InferredTypeTable.  It's OK if that table has an entry for a dangling StringImpl*, because all this means is that if some StringImpl gets allocated in the same memory address, we'll already have a hypothesis about the type.  It might be a wrong hypothesis, but that's still sound - at worst we'll come up with a looser type than what we could have done.  This might be a profitable optimization if the reduction in ref/deref traffic produced a big enough speed-up.

Anyway, it seems like IdentifierRepHash is doing either too much work in hash() or too little work in equal(), and we should fix it to be consistent, probably by just replacing it with PtrHash.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>