dicts,instances,containers, slotted instances, et cetera.

ocschwar at gmail.com ocschwar at gmail.com
Wed Jan 28 21:38:17 CET 2009

Hi, all.

I have an application that that creates, manipulates, and finally
archives on disk 10^6 instances of an object that in CS/DB terms is
best described as a relation.

It has 8 members, all of them common Python datatypes. 6 of these are
set once and then not modified. 2 are modified around 4 times before
the instance's archving. Large collections (of small lists) of these
objects are created, iterated through, and sorted using any and all of
the 8 members as sorting keys.

It neither has nor needs custom methods.

I used a simple dictionary to create the application prototype. Now I
need to speed things up.
I first tried changing to a new style class, with __slots__, __init__,
__getstate__& __setstate__ (for pickling) and was shocked to see
things SLOW down over dictionaries.

So of these options, where should I go first to satisfy my need for

0. Back to dict
1. old style class
2. new style class
3. new style class, with __slots__, with or without some nuance I'm
4. tuple, with constants to mark the indices
5. namedTuple
6. other...

More information about the Python-list mailing list