Re: decrease DictRow memory usage
James Henstridge <[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
2009/5/5 Oswaldo Hernández <[email protected]>: > Federico Di Gregorio escribió: >> >> Il giorno lun, 04/05/2009 alle 16.22 +0300, Marko Kreen ha scritto: >>> >>> Use "__slots__ = ('_index',)" to reserve single attribute slot for >>> _index. >>> Otherwise a per-row dict is created to store object attributes... >>> >>> The only danger of doing it is that if somebody uses plain DictRow and >>> adds new attrubutes into it, it will get error: >>> >>> row.foo = x >>> >>> I'm really dubious if anybody does this. NB, this does not apply if >>> somebody has subclassed DictRow, then the parent class' __slots__ >>> is ignored. >> >> I agree. I someone uses custom attributes on the DictRow let me know or >> I'll apply the patch. ;) >> > > Hi, > > I use a custom DictRow class derived from extras.DictRow. I will do this > afternoon some tests to overload '__slots__'. > > I will put here the results tomorrow. If you're subclassing DictRow then this change shouldn't have any effect on you. Your subclass will have an instance dictionary though, so you won't see the memory savings. If you want to see the memory savings though, you'll need to define __slots__ for your subclass. If you aren't adding any attributes, setting it to an empty tuple will do the trick. James.