[Python-Dev] Temporary Constantification
Guido van Rossum
guido at python.org
Mon Jun 26 01:29:41 CEST 2006
On 6/25/06, Eric Sumner <kd5bjo at gmail.com> wrote:
> On 6/25/06, Guido van Rossum <guido at python.org> 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
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/)
More information about the Python-Dev