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 carljm
Recipients Mark.Shannon, barry, brandtbucher, carljm, dino.viehland, gregory.p.smith, itamaro
Date 2022-03-04.21:24:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1646429070.83.0.193279505332.issue46896@roundup.psfhosted.org>
In-reply-to
Content
Thanks for the feedback!

> Why so coarse?

Simplicity of implementation is a strong advantage, all else equal :) And the coarse version is a) at least somewhat proven as useful and usable already by Cinder / Cinder JIT, and b) clearly doable without introducing memory or noticeable CPU overhead to unwatched dicts. Do you have thoughts about how you'd do a more granular version without overhead?

> Getting a notification for every change of a global in module, is likely to make use the use of global variables extremely expensive.

It's possible. We haven't ever observed this as an issue in practice, but we may have just not observed enough workloads with heavy writes to globals. I'd like to verify this problem with a real representative benchmark before making design decisions based on it, though. Calling a callback that is uninterested in a particular key doesn't need to be super-expensive if the callback is reasonably written, and this expense would occur only on the write path, for cases where the `global` keyword is used to rebind a global. I don't think it's common for idiomatic Python code to write to globals in perf-sensitive paths. Let's see how this shows up in pyperformance, if we try running it with all module globals dicts watched.

> For example, we could just tag the low bit of any pointer in a dictionary’s values that we want to be notified of changes to

Would you want to tag the value, or the key? If value, does that mean if the value is changed it would revert to unwatched unless you explicitly watched the new value?

I'm a bit concerned about the performance overhead this would create for use of dicts outside the write path, e.g. the need to mask off the watch bit of returned value pointers on lookup.

> What happens if a watched dictionary is modified in a callback?

It may be best to document that this isn't supported; it shouldn't be necessary or advisable for the intended uses of dict watching. That said, I think it should work fine if the callback can handle re-entrancy and doesn't create infinite recursion. Otherwise, I think it's a case of "you broke it, you get to keep all the pieces."

> How do you plan to implement this? Steal a bit from `ma_version_tag`

We currently steal the low bit from the version tag in Cinder; my plan was to keep that approach.

> You'd probably need a PEP to replace PEP 509, but I think this may need a PEP anyway.

I'd prefer to avoid coupling this to removal of the version tag. Then we get into issues of backward compatibility that this proposal otherwise avoids.

I don't think the current proposal is of a scope or level of user impact that should require a PEP, but I'm happy to write one if needed.
History
Date User Action Args
2022-03-04 21:24:30carljmsetrecipients: + carljm, barry, gregory.p.smith, dino.viehland, Mark.Shannon, brandtbucher, itamaro
2022-03-04 21:24:30carljmsetmessageid: <1646429070.83.0.193279505332.issue46896@roundup.psfhosted.org>
2022-03-04 21:24:30carljmlinkissue46896 messages
2022-03-04 21:24:30carljmcreate