This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients Dennis Sweeney, eamartin, rhettinger, zach.ware
Date 2021-02-11.05:40:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1613022022.13.0.947826571002.issue43198@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-02-11 05:40:22rhettingersetrecipients: + rhettinger, zach.ware, eamartin, Dennis Sweeney
2021-02-11 05:40:22rhettingersetmessageid: <1613022022.13.0.947826571002.issue43198@roundup.psfhosted.org>
2021-02-11 05:40:22rhettingerlinkissue43198 messages
2021-02-11 05:40:22rhettingercreate