[Python-Dev] Dictionary tuning

Delaney, Timothy C (Timothy) tdelaney@avaya.com
Tue, 29 Apr 2003 17:25:50 +1000


> From: Tim Peters [mailto:tim.one@comcast.net]
>=20
> [Delaney, Timothy C]
> > That's what I was getting at. I know that (for example) most
> > classes I create have less that 16 entries in their __dict__.
> > With this change, each class instance would take (approx) twice
> > as much memory for its __dict__. I suspect that class instance
> > __dict__ is the most common dictionary I use.
>=20
> Do they have fewer then 6 entries?  Dicts with 5 or fewer=20
> entries don't
> change size at all (an "empty dict" comes with room for 5 entries).

No hard and fast data here. That would require grovelling through code =
;)
I was making an quick estimate.

Off the top of my head, most classes I create have ...

__init__
3-5 other methods
3-5 instance attributes

Hmm - that would only be 3-5 instance __dict__ entries, with
4-6 class __dict__ entries, correct?

I was forgetting that methods are put into the instance __dict__.

Bah - it's too late. It's the end of the day, and I've barely
managed to get 2 hours real work done.

Tim Delaney