
On Sat, Jan 09, 2016 at 01:09:13PM +0100, M.-A. Lemburg wrote:
* 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 ?".
For an optimization it's good enough to get an answer "yes" for slow changing dicts and "no" for all other cases.
I don't understand this. The question has nothing to do with how quickly or slowly the dict has changed, but only on whether or not it actually has changed. Maybe your dict has been stable for three hours, except for one change; or it changes a thousand times a second. Either way, it has still changed.
False negatives don't really hurt. False positives are not allowed.
I think you have this backwards. False negatives potentially will introduce horrible bugs. A false negative means that you fail to notice when the dict has changed, when it actually has. ("Has the dict changed?" "No.") The result of that will be to apply the optimization when you shouldn't, and that is potentially catastrophic (the entirely wrong function is mysteriously called). A false positive means you wrongly think the dict has changed when it hasn't. ("Has the dict changed?" "Yes.") That's still bad, because you miss out on the possibility of applying the optimization when you actually could have, but it's not so bad. So false positives (wrongly thinking the dict has changed when it hasn't) can be permitted, but false negatives shouldn't be.
What you'd need to answer the question is a way for the code in need of the information to remember the dict state and then later compare it's remembered state with the now current state of the dict.
dicts could do this with a 16-bit index into an array of state object slots which are set by the code tracking the dict.
When it's time to check, the code would simply ask for the current index value and compare the state object in the array with the one it had set.
If I've understand that correctly, and I may not have, that will on detect (some?) insertions and deletions to the dict, but fail to detect when an existing key has a new value bound. -- Steve