[Python-Dev] speeding up PyObject_GetItem

Raymond Hettinger python at rcn.com
Tue Mar 24 10:46:31 CET 2009


>> Agreed, and more importantly, I have yet to be convinced that those NULL 
>> checks introduce a measurable slowdown.  Daniel, have you tried 
>> measuring the performance difference with only the NULL checks removed?

I think it highly unlikely that there is a performance difference.
These tend to branch the same way every time, so the 
processor's branch prediction will tend to reduce the check time
to near zero. 


> I think it would be fine to add a special case for lists (*) and dicts in
> PyObject_GetItem(), provided it does make a significant difference in
> performance for these two types.

-1

The API confusion and clutter isn't worth the micro-optimization.
Also, the checks probably do have some value in early detection
of programming errors; it would be ashamed to lose them in 
non-debug builds.  When we get bug reports that are due to 
problems with third-party extensions, it will be harder to know
whether the issue is with the extension or with us.


Raymond


More information about the Python-Dev mailing list