[Python-Dev] Possible optimization for LOAD_FAST ?

Guido van Rossum guido at python.org
Tue Jan 4 23:30:36 CET 2011

On Tue, Jan 4, 2011 at 2:15 PM, Daniel Stutzbach <stutzbach at google.com> wrote:
> On Tue, Jan 4, 2011 at 9:33 AM, Lukas Lueg <lukas.lueg at googlemail.com>
> wrote:
>> The keys are immutable anyway so the instances of PyDict could manage
>> a opaque value (in fact, a counter) that changes every time a new
>> value is written to any key. Once we get a reference out of the dict,
>> we can can do very fast lookups by passing the key, the reference we
>> know from the last lookup and our last state. The lookup returns a new
>> reference and the new state.
>> If the dict has not changed, the state doesnt change and the reference
>> is simply taken from the passed value passed to the lookup. That way
>> the code remains the same no matter if the dict has changed or not.
> I have had similar ideas in the past but have never found time to explore
> them.  The same mechanism could also be used to speed up attribute access on
> objects.

Check out the various approaches in PEP 266, PEP 267, and PEP 280.

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

More information about the Python-Dev mailing list