Message371048
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? |
|
Date |
User |
Action |
Args |
2020-06-08 22:48:32 | Dennis Sweeney | set | recipients:
+ Dennis Sweeney, rhettinger, serhiy.storchaka |
2020-06-08 22:48:32 | Dennis Sweeney | set | messageid: <1591656512.01.0.515498863518.issue40889@roundup.psfhosted.org> |
2020-06-08 22:48:32 | Dennis Sweeney | link | issue40889 messages |
2020-06-08 22:48:31 | Dennis Sweeney | create | |
|