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 Mark.Shannon
Recipients Mark.Shannon, brandtbucher, erlendaasland, methane, vstinner
Date 2021-05-25.11:13:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Which optimizations?

Using a keys version instead of a whole dict version means that LOAD_GLOBAL won't leak references. It also means that we can (in the future) remove the PEP 509 version and save 8 bytes per dict.

_PyDict_GetItemHint() still has to do quite a lot of work compared to a version check.
The hint approach can't quickly tell us whether a name is not in a dictionary, which is needed for optimizing non-descriptor class attributes.

Because functions are non-overriding descriptors we need to quickly check that the instance does not have an attribute shadowing the method.

Why is 32 bits enough?

Because the version is reset to zero, whenever the dict keys changes, and only set to non-zero when we explicitly ask for it when optimizing. 4 billion optimization events is a lot.
It can't overflow, it just becomes useless when we reach UINT_MAX.
Using 64 bits would just waste memory.

Overall, versioning the dictionary's keys is more useful and more compact than versioning the dictionary as a whole.
Date User Action Args
2021-05-25 11:13:20Mark.Shannonsetrecipients: + Mark.Shannon, vstinner, methane, brandtbucher, erlendaasland
2021-05-25 11:13:20Mark.Shannonsetmessageid: <>
2021-05-25 11:13:20Mark.Shannonlinkissue44206 messages
2021-05-25 11:13:19Mark.Shannoncreate