[Python-Dev] Possible optimization for LOAD_FAST ?

Guido van Rossum guido at python.org
Mon Jan 3 17:01:31 CET 2011


On Mon, Jan 3, 2011 at 6:12 AM, Glyph Lefkowitz <glyph at twistedmatrix.com> wrote:
> Wouldn't this optimization break things like mocking out 'open' for testing via 'module.open = fakeopen'?  I confess I haven't ever wanted to change 'len' but that one seems pretty useful.

I am explicitly excluding open from this optimization, for that very reason.

> If CPython wants such optimizations, it should do what PyPy and its ilk do, which is to notice the assignment, but recompile code in that module to disable the fast path at runtime, preserving the existing semantics.

In general I am against duplicating bytecode -- it can blow up too
much. (It is an entirely appropriate technique for JIT compilers --
but my point here is that bytecode is different.) Recompiling a module
is not a trivial change -- for example, either code objects would have
to become mutable, or we'd have to track down all the code objects and
replace them. Neither sounds attractive to me.

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list