-
Type: Sub-task
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: Internal Code
-
Service Arch
-
Fully Compatible
StringData::ComparatorInterface and most of its callers can be improved in several respects. I want to open this ticket to give the StringData::ComparatorInterface some attention. It's used in some very important places.
Move it out of the StringData class to be a first-class type. StringData::ComparatorInterface is not part of what StringData is. It's just one particular thing you can do with StringData. We already have a separate file for its definition, `mongo/base/string_data_comparator_interface.h`, so we can essentially rename `StringData::ComparatorInterface` to `StringDataComparator` in that file. We can remove "Interface" from the name. I'm looking at the typedefs:
StringDataUnorderedSet
StringDataUnorderedMap
And they are hard to use correctly because their hasher and key_eq functors are stateful, so a factory function is needed, and the functors provided have lifetime caveats on an underlying StringData::ComparatorInterface everybody just uses the singleton kInstance, so the whole thing can just be a family of matched stateless functors for every use in the codebase. Many can now be migrated to use stdx::unordered_map and stdx::unordered_set and be more efficient.
The StringDataComparatorInterface is missing an equal virtual function. It has a compare and a hash_combine but no equal. This means that doing hash container lookups will have to use compare, which is potentially far more expensive than == on StringData, as equality can short-circuit in the case of unequal string lengths.
- is related to
-
SERVER-77698 Replace MurmurHash3 with absl::Hash if possible in SimpleStringDataComparator::hash_combine
- Blocked
- related to
-
SERVER-32422 convert StringData to std::string_view
- Backlog