Potential redundant key comparisons in flat_hash_map::operator== #1903
HUD-Software
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
While profiling code comparing two flat_hash_map instances, I noticed that during the execution of operator==, each key seems to be compared twice:
First, when calling find() on the second map to locate the corresponding element.
Then, when comparing the value_type (i.e., std::pair<const Key, Value>) objects themselves, which compares both key and value.
Since the key has already been looked up via find(), this second key comparison seems redundant.
Is this expected behavior for compatibility/generalization reasons, or would you consider optimizing operator== to avoid comparing the key twice when possible?
Example of optimized pseudocode (to avoid redundant key comparison):
I’m aware that the current implementation probably favors code generality and reusability, but given that flat_hash_map aims for performance, this might be an area worth considering.
What’s your take on this?
Thanks again for your work!
Beta Was this translation helpful? Give feedback.
All reactions