[Python-Dev] Simple dicts

Guido van Rossum guido@python.org
Thu, 15 May 2003 20:27:58 -0400


> There seem to be two different ways to get/set/del from a dictionary.
> 
> The first is using PyDict_[Get|Set|Del]Item()

This is the API that all C code uses (except code that doesn't know
whether it's dealing with dicts or some other mapping, which has to
use PyObject_GetItem() etc, which is even slower).

> The second is using the embarssingly named dict_ass_sub() and its
> partner dict_subscript().

This is what PyObject_GetItem() calls.

> Which of these two access methods is most likely to be used?

That's a hard question.  Maybe a profiler can answer.  The thing is,
there's a lot of C code that calls PyDict_GetItem() directly, e.g. the
attribute lookup code.  Bot of course there's also a lot of Python
code using dicts.

Yet, I'd bet on PyDict_*().

--Guido van Rossum (home page: http://www.python.org/~guido/)