[Pyrex] Pyrex optimization chitchat

Paul Prescod paul at prescod.net
Thu Jan 22 04:08:51 CET 2004


Greg Ewing wrote:

> Paul Prescod:
> 
> 
>>cdef x(list foo):
>>	foo.append(5)
>>
>>Should the compiler expand that to optimized PyList_Append code or call 
>>a method by name?
> 
> 
> I think it really has to do a method lookup. Even if foo is
> declared to be a list, it might be a subclass of list that
> overrides the append method.
> 
> It might be worth having some special Pyrex builtins such
> as listappend for things like this.

That was my conclusion also. Just as there are "functional" versions in 
the Python C API there could be Pyrex functions.

I don't know if they need to be builtin as in "in the builtin 
namespace". People should only use them where they value performance 
over dynamicity. Using them too much obfuscates Pyrex code, makes it 
look too different than Python and makes subclasses work "wrong". All of 
which is okay if the programmer understands the tradeoffs.

  Paul Prescod






More information about the Pyrex mailing list