On Nov 3, 2009, at 2:37 PM, Lisandro Dalcin wrote:

> On Tue, Nov 3, 2009 at 4:20 PM, Robert Bradshaw
> <[email protected]> wrote:
>> I concede that we're partially copying the (half-line) list-shrink  
>> trigger
>> algorithm here, but if that changed nothing would break. It's not  
>> like we're
>> using any secret APIs.
>>
>
> So L->allocated is public API? If you can get rid of that, I think no
> one would object your patch...

Well, it's clearly documented in listobject.h, and we didn't have to  
import any special headers to get it (like we do for frame objects and  
exception handling). There's nothing clean and simple to use instead,  
at least not without giving up nearly all the potential savings.

>> For the no argument case, there really is hardly any code  
>> duplication. Also,
>> we don't do any reallocation or anything, we just note that if the  
>> number of
>> items get small enough we dispatch to the generic case. I think the
>> resulting 5x speedup is worth it.
>>
>>> Why not use PyList_GET_ITEM(L) + Py_INCREF() + PyList_SetSlice() ??
>>> This way, you could easily support "L.pop(index)"...
>>
>> Have you seen the code for PyList_SetSlice? It's way more generic  
>> (and
>> complicated) than is needed in this case. And if one were to use  
>> the methods
>> mentioned above, one would still need all the bounds checking code  
>> that's
>> there (the only savings would be calling PyList_SetSlice rather  
>> than having
>> a manual loop, at the expense of extra memory management). Again,  
>> I'd argue
>> it's worth an 10x speedup.
>>
>
> Robert, "premature optimization is the root of all evil"... You are
> trying to be faster than CPython!! list.pop() is implemented more or
> less with PyList_SetSlice !!

You say this as if it's a bad thing to be faster than CPython :)

>> Ideally there should be a PyList_Pop method in the C API, and more  
>> efficient
>> than the one that's there, but that's not the case.
>
> Yes, of course... And if it were, it would likely be implemented with
> PyList_SetSlice, as the list.pop() method is currently is... Or core
> CPython devs are truly lazy, or you Robert are wasting valuable time
> in micro-optimizations ...

Well, at least I spent less time on that micro-optimization than  
answering these emails :). (Not that I think that either is a waste.)  
My hunch is that since there was no (natural) way to pop without a  
Python function call, and the attribute lookup and argument unpacking  
took more time each than the PyList_SetSlice code overhead, there was  
no incentive for the core CPython devs to put any time into optimizing  
this, if it even crossed their radar.

- Robert

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to