[Python-Dev] Identifier API

Victor Stinner victor.stinner at haypocalc.com
Thu Oct 13 03:34:00 CEST 2011


Le jeudi 13 octobre 2011 00:44:33, Victor Stinner a écrit :
> Le samedi 8 octobre 2011 16:54:06, Martin v. Löwis a écrit :
> > In benchmarking PEP 393, I noticed that many UTF-8 decode
> > calls originate from C code with static strings, in particular
> > PyObject_CallMethod. Many of such calls already have been optimized
> > to cache a string object, however, PyObject_CallMethod remains
> > unoptimized since it requires a char*.
> 
> Because all identifiers are ASCII (in the C code base), another idea is to
> use a structure similar to PyASCIIObject but with an additional pointer to
> the constant char* string:

Oh, I realized that Martin did already commit its PyIdentifier API, it's maybe 
too late :-)

> We would need a new format for Py_BuildValue, e.g. 'a' for ASCII string.
> Later we can add new functions like _PyDict_GetASCII().

The main difference between my new "const ASCII" string idea and PyIdentifier is 
the lifetime of objects. Using "const ASCII" strings, the strings are 
destroyed quickly (to not waste memory), whereas PyIdentifiers are intern 
strings and so they are only destroyed at Python exit.

I don't know if "const ASCII" strings solve a real issue. I implemented my 
idea. I will do some benchmarks to check if it's useful or not :-)

Victor


More information about the Python-Dev mailing list