On 6/25/06, Eric Sumner <[EMAIL PROTECTED]> wrote: > On 6/25/06, Guido van Rossum <[EMAIL PROTECTED]> wrote: > > Unfortunately, a mechanism that would let you register a callback for > > when a particular variable or attribute used in a cached expression is > > used, is pretty hard to implement without affecting the performance of > > code that doesn't use it. I'm afraid this is not a very likely path > > towards a solution. > > I could make a strong argument that it is actually impossible to > implement without affecting the performance of other code; the only > issue is whether or not the impact is acceptable. I may be wrong, but > I think that this particular scheme minimizes the impact: > - There is a bit more data to store in every namespace > - There is no change to dereferencing names; no test is required, no > callback is generated > - Binding to a name that currently has no binding simply requires > allocating the extra memory and clearing it. > - Binding to a name that is bound and does have callbacks is slow, > but those are supposed to be constant *in practice* anyway. > - Binding to a name that is already bound, but has no callbacks > requires a test on a single variable against a constant. > > Without knowing more about the internals of Python (such as how long a > check of a single variable takes relative to binding a new value to a > name), I can't properly evaluate how much of a problem this would be.
Your proposal would require a change to the dict type to set a callback to be called when a particular key is modified (not a generic callback when any key is modified). That seems pretty tricky to do with no impact, given how highly dicts are optimized. Also, allowing attribute references is a whole new can of worms, since attributes aren't necessarily implemented as standard namespaces implemented by dictionaries. Aahz already pointed this out. -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com