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 <1621941200.33.0.167537197602.issue44206@roundup.psfhosted.org>
In-reply-to
Content
Which optimizations?

LOAD_GLOBAL:
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.

LOAD_ATTR:
_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.

LOAD_METHOD:
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.
History
Date User Action Args
2021-05-25 11:13:20Mark.Shannonsetrecipients: + Mark.Shannon, vstinner, methane, brandtbucher, erlendaasland
2021-05-25 11:13:20Mark.Shannonsetmessageid: <1621941200.33.0.167537197602.issue44206@roundup.psfhosted.org>
2021-05-25 11:13:20Mark.Shannonlinkissue44206 messages
2021-05-25 11:13:19Mark.Shannoncreate