On Wed, Nov 10, 2010 at 12:07:00PM +0100, Charlie Clark wrote: > Am 10.11.2010, 01:40 Uhr, schrieb Brian Sutherland > <br...@vanguardistas.net>: > > >> > On the micro benchmarks, the only difference I see is a memory > >> > improvement which I think will not survive in practice because most > >> > >> ... ? > > Er, somehow my thoughts didn't make it into text: > > attributes are zope.schema fields (i.e. subclasses of Attribute). > > To really make that work, you'd have to add __slots__ to most of the > > classes in zope.schema as well. > > It might be purely academic but if this does significantly reduce memory > use then it might be worth pursuing.
Turns out it's not that academic. I tried a bit harder and managed to apply __slots__ to the Element, Attribute and Method classes in zope.interface. That saved an additional 0.5 % of memory (bytes). I have a small patch to zope.schema that fixes the breakage there. It looks like there is an additional 0.5% available if zope.schema is refactored to use slots as well. > Slots are supposed to be beneficial > when you've got lots of objects around. Zope schema fields are pretty > static anyway so I don't see a great penalty in having to add slots to > them, although obviously a migration of a larger project would probably be > a pain. Searching for __dict__ here: http://zope3.pov.lt/trac/browser/zope.schema/trunk/src/zope/schema/_bootstrapfields.py Will give you a good idea of the problems. Field.bind and ValidatedProperty both depend heavily on __dict__. For ValidatedProperty in particular I have no idea how that would work when using slots. > Back to the micro-optimisation. At Jeff Rush's talk at PyCon this year he > covered the penalties incurred by "." lookups so that might be something > that could be investigated but might it also be possible to "memoize" the > method calls? I keep forgetting when you can't do that. I had a look at http://en.wikipedia.org/wiki/Memoization, but I don't see how it could be applied in this case. > Charlie > -- > Charlie Clark > Managing Director > Clark Consulting & Research > German Office > Helmholtzstr. 20 > Düsseldorf > D- 40215 > Tel: +49-211-600-3657 > Mobile: +49-178-782-6226 > _______________________________________________ > Zope-Dev maillist - Zope-Dev@zope.org > https://mail.zope.org/mailman/listinfo/zope-dev > ** No cross posts or HTML encoding! ** > (Related lists - > https://mail.zope.org/mailman/listinfo/zope-announce > https://mail.zope.org/mailman/listinfo/zope ) -- Brian Sutherland _______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org https://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - https://mail.zope.org/mailman/listinfo/zope-announce https://mail.zope.org/mailman/listinfo/zope )