gh-112075: Iterating a dict shouldn't require locks by DinoV · Pull Request #115108 · python/cpython
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to avoid expensive atomic operations, like atomic compare exchange and atomic increments, as well as avoiding locking.
This means giving up some atomicity for list and dict iterators compared to the GIL behavior. We should still avoid crashes/memory corruption, but I think it's okay for concurrent calls to next(it) on the same iterator object to return the same object. These iterators are almost always used by only a single thread and the performance cost of making the next atomic is relatively high.
See #114843 for the list iterator changes.