[issue43198] Operations on sets more than hundred times less efficient with python3.9 than with previous versions

Raymond Hettinger report at bugs.python.org
Thu Feb 11 00:40:22 EST 2021


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

This only affects the contrived case of adding and removing exactly the same element in a tight loop, when the set is large.  Optimizing that one corner case came at the expense of all other cases.  The code is now simpler and slightly faster than before.  This is also what we do for dictionaries.

$ python3.8 -m timeit -r 11 -s 's=set(range(10_000))' 'for i in range(10_000): (s.discard(i), s.add(10_000 - i))'
200 loops, best of 11: 1.72 msec per loop

$ python3.9 -m timeit -r 11 -s 's=set(range(10_000))' 'for i in range(10_000): (s.discard(i), s.add(10_000 - i))'
200 loops, best of 11: 1.09 msec per loop

Thank you for the report, but this was an intended change.

----------
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43198>
_______________________________________


More information about the Python-bugs-list mailing list