Accessing __slots__ from C

Hrvoje Niksic hniksic at xemacs.org
Fri Sep 12 09:53:51 EDT 2008


Chris <ceball at users.sourceforge.net> writes:

>> In my experience, as long as you're
>> accessing simple slots, you should notice a difference.
>
> (I'm not sure what you mean by a 'simple slot'.

I mean a slot defined by __slots__ = slot1, slot2, slot3, ..., without
descriptors or specific __getattribute__ code on top of that.

> - GetAttr: 46 seconds (46 seconds)
> outside the loop:
> PyObject *name = PyString_FromString("attr_one"); 

I think you should be using PyString_InternFromString, but it will
probably still be slower than PyList_GET_ITEM, which is still much
simpler.  The next optimization is the one proposed by Carl, which
should yield speed comparable to PyList_GET_ITEM.  See my response in
that subthread for details.



More information about the Python-list mailing list