![](https://secure.gravatar.com/avatar/bfc96d2a02d9113edb992eb96c205c5a.jpg?s=120&d=mm&r=g)
On Sat, Dec 17, 2011 at 2:31 PM, Dirkjan Ochtman <dirkjan@ochtman.nl> wrote:
On Sat, Dec 17, 2011 at 12:53, Maciej Fijalkowski <fijall@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 :)