
Marc-Andre Lemburg:
* Given that this is an optimization and not meant to be exact science, why would we need 64 bits worth of version information ?
AFAIK, you only need the version information to be able to answer the question "did anything change compared to last time I looked ?". (...)
Gregory P. Smith <greg@krypto.org>:
Given it is for optimization only with the fallback slow path being to do an actual dict lookup, we could implement this using a single bit.
You misunderstood the purpose of the PEP. The purpose is to implement fast guards by avoiding dict lookups in the common case (when watched keys are not modified) because dict lookups are fast, but still slower than reading a field of a C structure and an integer comparison. See the result of my microbenchmark: https://www.python.org/dev/peps/pep-0509/#implementation We are talking about a nanoseconds. For the optimizations that I implemented in FAT Python, I bet that watched keys are rarely modified. But it's common to modify the watched namespaces. For example, a global namespace can be modified by the "lazy module import" pattern: "global module; if module is None: import module". Or a global variable can be a counter used to generate identifiers, counter modified regulary with "global counter; counter = counter + 1" which changes the dictionary version.
* Wouldn't it be possible to use the hash array itself to store the state index ?
We could store the state object as regular key in the dict and filter this out when accessing the dict.
Alternatively, we could try to use the free slots for storing these state objects by e.g. declaring a free slot as being NULL or a pointer to a state object.
I'm sorry, I don't understand this idea. Victor