Eliminate __dict__ from persistent btree, bnode,
dict, list and set
Patrick K. O'Brien
2006-07-05
Patrick K. O'Brien wrote:
> I have a version of Durus 3.3 working with modified versions of btree,
> bnode, dict, and so forth that have no __dict__ (only slots) to save the
> memory space of this extra, unnecessary dictionary. I'm currently
> working on the same thing for Durus 3.4.1.
The modification for Durus 3.4.1 is done. The files are customized for
Schevo and can be found in this branch:
http://schevo.org/trac/browser/branches/gtk-
support-3/Schevo/schevo/store?rev=2282
The basic idea behind my approach is embodied in this base class, which
I used as the base class for PersistentDict and PersistentList:
class PersistentData(Persistent):
__slots__ = ['data', '__weakref__']
def __getstate__(self):
return dict(data=self.data)
def __setstate__(self, state):
self.data = state['data']
__delattr__ = object.__delattr__
__setattr__ = object.__setattr__
def _p_set_status_ghost(self):
del self.data
self._p_status = GHOST
The btree and bnode classes were modified in a similar fashion, and
PersistentSet was modified to be compatible with Dict and List so it
could subclass PeristentData as well.
Any reason not to incorporate this idea into Durus itself? The only
change required on the Persistent class was to define __slots__ on it.
But this shouldn't have any impact on custom subclasses. So I think
these changes could be made to Durus in a completely backward compatible
fashion. Thoughts? Reactions?
--
Patrick K. O'Brien
Orbtech http://www.orbtech.com
Schevo http://www.schevo.org
Louie http://www.pylouie.org