[SERVER-68837] TenantId absl hashing is inefficient Created: 15/Aug/22  Updated: 29/Oct/23  Resolved: 07/Sep/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 6.2.0-rc0

Type: Improvement Priority: Major - P3
Reporter: Billy Donahue Assignee: Adi Agrawal
Resolution: Fixed Votes: 0
Labels: neweng, ordered
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Server Serverless 2022-08-22, Server Serverless 2022-09-05, Server Serverless 2022-09-19
Participants:

 Description   

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.



 Comments   
Comment by Githook User [ 07/Sep/22 ]

Author:

{'name': 'Adityavardhan Agrawal', 'email': 'aa729@cornell.edu', 'username': 'Adityav369'}

Message: SERVER-68837: removed the double hashing in AbslHashValue for TenantId
Branch: master
https://github.com/mongodb/mongo/commit/a40f6505e1a1ac8f886cb5946ca00e60ac4d3c41

Generated at Thu Feb 08 06:11:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.