Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-68837

TenantId absl hashing is inefficient

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.2.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Fully Compatible
    • Server Serverless 2022-08-22, Server Serverless 2022-09-05, Server Serverless 2022-09-19

      absl's Hash::combine functions are already hashing.
      What we're doing is adding a tenantId's hash to the hash,
      which is hashing twice.

          std::size_t hash() const {
              return OID::Hasher()(_oid);
          }
      
          /**
           * Functor compatible with std::hash for std::unordered_{map,set}
           */
          struct Hasher {
              std::size_t operator()(const TenantId& tenantId) const {
                  return tenantId.hash();
              }
          };
      
          /**
           * Hash function compatible with absl::Hash for absl::unordered_{map,set}
           */
          template <typename H>
          friend H AbslHashValue(H h, const TenantId& tenantId) {
              return H::combine(std::move(h), tenantId.hash());
          }
      

      The idiom for absl's composable hashing would be that you combine the _oid directly to h and then OID would have its own AbslHashValue nonmember function that ultimately combines in the bytes of the _oid as a range.

            Assignee:
            adi.agrawal@mongodb.com Adi Agrawal
            Reporter:
            billy.donahue@mongodb.com Billy Donahue
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: