[Python-Dev] Temporary Constantification

Eric Sumner kd5bjo at gmail.com
Mon Jun 26 01:17:47 CEST 2006


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.

  -- Eric Sumner


More information about the Python-Dev mailing list