[Python-Dev] Q: why doesn't list.extend use the sequence interface?

M.-A. Lemburg mal@lemburg.com
Sat, 17 Jun 2000 10:41:25 +0200


Mark Hammond wrote:
> 
> /F:
> > just for the record, I just changed some generic sequence code
> > to something like:
> ...
> > so in other words, this construct is more than 4 times faster
> > than plain use of PySequence_GetItem.
> 
> Good stuff!
> 
> > guess it's time to fix a couple of things in PIL...
> 
> Its a fair bit of code to duplicate everywhere you want the speed increase.
> How can we add a similar scheme to the core, so the changes people need to
> make are trivial (to the point where the change is zero!)?

We could add special code the standard type to PySequence_GetItem()
et al., but it would still cause a C function call (not much,
but noticable in inner loops).

How about adding some inline markers to the most often
used (and small) routines in the medium level abstract interface
(PySequence_*, PyMapping_*, etc.) ?!

Together with the special code for the native Python types
this should yield a speedup for all extensions by simple
virtue of a recompile... OTOH, changes to these APIs would
need a recompile of the extensions too.

BTW, I've used the same approach as Fredrik in mx.Tools.
It does make great a difference...

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/