Ian, I had not yet done any testing when I emailed you that patch originally.
When I did some testing the other day in order to determine what difference, if any, the __slots__ attribute made, the results were surprising. My application using the __slots__ patched version of urwid used 4-5 megs more ram than the unpatched version. I am not totally sure why this is; as I explained before, the __slots__ attribute reduces an object's memory footprint by changing the data structure of attributes from a dict to a tuple. My first thought is that it may be from pre-allocating the memory space for the _urwid_signals attribute on every object for the new way you're doing signals, and that pre-allocation on every widget eliminates any previous gains. Switching signals back to the previous implementation may solve the problem. As for my testing methodology, I loaded up the mail program I've been developing using Urwid and loaded all conversations in my email. Doing this loaded ~2650 AttrMap wrapped Text widgets into a Listbox. Once all the widgets were loaded I did ps aux in another terminal and looked at the RSS field. My program using an unmodified version of Urwid used ~143000k of ram. My program using Urwid with my patch used ~148000k of ram. Dominic On Wed, Nov 11, 2009 at 5:44 AM, Ian Ward <[email protected]> wrote: > Dominic LoBue wrote: > > As you suggested when I mentioned including __slots__, I went through >> Urwid and added the __slots__ attribute where it made sense. >> >> Attached is a mercurial export of my changes. I've been using that >> code all day today with my program and have worked out most of the >> snags. The only problem I'm aware of is with the LineBox widget, I get >> this error: >> TypeError: Error when calling the metaclass bases >> multiple bases have instance lay-out conflict >> >> I tried looking for a simple fix to get it working, but frankly it >> made my brain hurt. >.< I finally gave in and just commented the >> widget out since I wasn't using it anyway, and everything else worked. >> Maybe you'll have an idea for a fix. > > I'm unfamiliar with __slots__, but it looks like it would break any kind > of multiple inheritance. It also would cause a problem any time you > want to add an attribute that wasn't declared. > > What are the memory footprint gains you are seeing by using __slots__? > How are you measuring them? > > I think they may only be appropriate for some classes, like the canvas > classes, and things like AttrSpec that really only ever have a few > attributes, and there is no need to subclass them. > > Ian > > > _______________________________________________ > Urwid mailing list > [email protected] > http://lists.excess.org/mailman/listinfo/urwid > > _______________________________________________ Urwid mailing list [email protected] http://lists.excess.org/mailman/listinfo/urwid
