Lisandro Dalcin, 31.10.2009 22:12:
> On Sat, Oct 31, 2009 at 10:18 AM, Stefan Behnel wrote:
>> To fix this, I pushed a change that optimises this
>>
>>        cdef type some_type = ...
>>        obj = some_type.__new__(some_type)
>>
> 
> So it seems that the optimization only works if __new__ is called with
> just a single arg some_type... but your __new__ optimization will
> definitely call __cinit__. Do you think that optimizing a many-args
> __cinit__ is a nonsense?

Not nonsense, but certainly less important. Since the arguments are passed
as Python arguments in that case, it doesn't really fit the use case of
fast instantiation. Without having benchmarked it any recently, I assume
it's still quite a bit faster to do

        cdef MyType obj = MyType.__new__(MyType)
        obj.some_attr = something

than to do

        cdef MyType obj = MyType.__new__(MyType, something)

and set the attribute in __cinit__(). It may not be that a big difference
if you are only passing Python arguments, but it certainly is a bigger
difference if you additionally need to convert arguments from C types to
Python types and back, just to get them passed into __cinit__().

So I assume that the main use case is fast instantiation from within a
factory function.


> BTW, You did not taken into account __cinit__ special method in your
> testing... I've tried to add __cinit__ in your testcase with a "print"
> inside, but I do not know why the test hangs (this is a bit strange,
> isn't it?)...

I added that to the tests and it absolutely works for me.

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

Reply via email to