[Python-Dev] A new dict for Xmas?

Maciej Fijalkowski fijall at gmail.com
Sat Dec 17 13:34:52 CET 2011


On Sat, Dec 17, 2011 at 2:31 PM, Dirkjan Ochtman <dirkjan at ochtman.nl> wrote:
> On Sat, Dec 17, 2011 at 12:53, Maciej Fijalkowski <fijall at gmail.com> wrote:
>> Note that unlike some other more advanced approaches, slots do change
>> semantics. There are many cases out there where people would stuff
>> arbitrary things on stdlib objects and this works fine without
>> __slots__, but will stop working as soon as you introduce them. A
>> change from no slots to using slots is not only a performance issue.
>
> Yeah... This whole idea reeks of polymorphic inline caches (called
> "shapes" or "hidden classes" in SpiderMonkey and v8, respectively),
> where they dynamically try to infer what kind of class an object has,
> such that the __slots__ optimization can be done without making it
> visible in the semantics. The Unladen Swallow guys mention in their
> ProjectPlan that the overhead of opcode fetch/dispatch makes that
> hard, though.
>
> Cheers,
>
> Dirkjan

It's done in PyPy btw. Works like a charm :) It's called sharing dict
and the idea dates back to self and it's maps. There is also an
ongoing effort to specialize on types of fields, so you don't have to
box say ints stored on classes. That's however in-progress now :)


More information about the Python-Dev mailing list