Dennis Sweeney <[email protected]> added the comment:
A demo:
>>> class Int(int):
... hash_calls = 0
... def __hash__(self):
... Int.hash_calls += 1
... return super().__hash__()
...
>>> left = {Int(1): -1, Int(2): -2, Int(3): -3, Int(4): -4, Int(5): -5, Int(6):
>>> -6, Int(7): -7}
>>> right = {Int(1): -1, Int(2): -2, Int(3): -3, Int(4): -4, Int(5): -5,
>>> Int(8): -8, Int(9): -9}
>>> Int.hash_calls = 0
>>> left.items() ^ right.items()
{(9, -9), (7, -7), (8, -8), (6, -6)}
>>> Int.hash_calls
<Result: 14 on Master, but only 4 on PR 20718>
It looks like the same trick (searching by key and comparing values before
maybe constructing a 2-tuple) might give similar performance improvements for
dict_items.__or__, dict_items.__and__, and dict_items.__sub__. Is it worth
discussing these other operators in this issue?
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue40889>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com