[ZODB-Dev] persisting "immutable" classes

John Belmonte john at neggie.net
Sat Feb 28 12:29:51 EST 2004


Jeremy Hylton wrote:
> The other issue to be aware of is that the immutable object is persisted
> by value instead of by reference.  [...]
> 
> Another issue to consider is how many objects are instantiated when a
> first-class object is loaded.   [...]
> 
> As far for the space overhead, I recently added a comment to
> cPersistence.h that describes the space overhead:
> 
> /* How big is a persistent object?
>  
>    12  PyGC_Head is two pointers and an int
>     8  PyObject_HEAD is an int and a pointer
>   
>    12  jar, oid, cache pointers
>     8  ring struct
>     8  serialno
>     4  state + extra
>  
>   (52) so far
>  
>     4  dict ptr
>     4  weaklist ptr
>   -------------------------
>    64  only need 62, but obmalloc rounds up to multiple of eight
>                                                                                 
>   Even a ghost requires 64 bytes.  It's possible to make a persistent
>   instance with slots and no dict, which changes the storage needed.
>                                                                                 
> */
> 
> There are other costs to consider:
> 144 bytes for instance dict (holding up to 5 attrs) (if the object is
> not a ghost)
> 28 bytes for PyStringObject for 8-byte oid

Thanks, that's very helpful.  It seems like the space for the instance 
dictionary is 2x the Persistent object overhead.  So considering my 
example of a time+ID key class, assuming that it has only a couple 
attributes and is not shared:

   * as a quick solution, a first-class object with slots has less space 
overhead than a second-class object without slots

   * as an optimal solution, given that tens of thousands of these keys 
may exist, use a second-class object with slots (by defining my own 
get/setstate)

-John


-- 
http:// if  ile.org/



More information about the ZODB-Dev mailing list