[Python-ideas] Put default setstate and getstate on object for use in coöperative inheritance.
Nick Coghlan
ncoghlan at gmail.com
Sat Jun 7 11:34:03 CEST 2014
On 7 June 2014 18:46, Neil Girdhar <mistersheik at gmail.com> wrote:
>
> Right, that makes sense. I think the flyweight pattern would eliminate
> this: use a special representation for the common case and then switch to a
> real representation as soon as things become weird. (I can see how that
> would be extra development time unless it could be done automatically by a
> clever JIT.)
The flyweight pattern imposes its own costs in terms of additional
levels of indirection and even more pointers to carry around. The
approach we take is that object instances get a __dict__ attribute by
default, unless the creator of the class decides "there are going to
be enough of these for it to be worth skipping the space not only for
the attribute dicts themselves, but also for the attribute dict
reference on each instance". We do the same with weakref support.
The other thing to keep in mind is that many of CPython's "internal"
representations aren't actually internal: many of them are exposed in
various ways through the CPython C API. As other implementations have
discovered, preserving full compatibility with that API places some
pretty significant constraints on the implementation techniques you
use (or else means putting a lot of work into a compatibility shim
layer like IronClad, JyNI or cpyext).
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list