[ZODB-Dev] Subclassing dict vs. PersistentMapping

Thomas Guettler guettli at thomas-guettler.de
Sat May 31 12:42:40 EDT 2003


On Fri, May 30, 2003 at 11:45:57AM -0400, Jeremy Hylton wrote:
> On Fri, 2003-05-30 at 11:35, Thomas Guettler wrote:
> > Hi!
> > 
> > I compared the size of data.fs. Strange but true, inheriting from dict
> > instead of PersistentMapping makes the database file bigger. I thought
> > inheriting from dict should make the database smaller.
> > 
> > The dict-database was about 25% bigger.
> > 
> > Can someone explain this?
> 
> I think someone would need more explanation of what you're doing to make
> sense of it.  I'm not sure how the subclass of dict worked, but I don't
> see how it could be a persistent object.  If so, then a copy of the dict
> would get saved with every persistent object that references it.  In the
> presence of sharing, you'd get multiple, divergent copies of the
> object.  That would make the database bigger.

I try to explain it with some code:

Doc map like a dictionary: Column --> Value

#class Doc(PersistentMapping): #(data.fs smaller)
class Doc(dict):               #(data.fs bigger)
    #docs get created with the constructor of the parent class
    #they never get changed.
    #key and value are strings
    pass

SearchContainer has a search interface: 
    "Give me all docs where column1=value1"
It holds a BTree for every column.

Swiching the parent class of Doc changed the size of the data.fs file.

Maybe you are right, that the doc object got copied. Since the don't
change I did not realize notice it. 

 thomas

-- 
Thomas Guettler <guettli at thomas-guettler.de>
http://www.thomas-guettler.de




More information about the ZODB-Dev mailing list