[Cython] Optimising dict manipulation in extension types
Aaron DeVore
aaron.devore at gmail.com
Sun Nov 9 05:38:28 CET 2008
I'm not sure if this solves the problem but it would help if you
declared your variables with an actual type (list, tuple, dict, etc.)
instead of just 'object'. That allows Cython to do optimizations like
substituting PyList_Append(new_env, obj) for the more expensive
new_env.append(obj).
On Sat, Nov 8, 2008 at 8:13 PM, tav <tav at espians.com> wrote:
> Whilst I'm at it, is there any advantage into turning the various
> lists into C arrays? I won't be accessing them from Python and thus
> was wondering if it would also be possible to speed up the
> __getattribute__ implementation in Namespace? Thanks!
>
> Do you guys hang out on IRC at all?
>
> On Sun, Nov 9, 2008 at 3:56 AM, tav <tav at espians.com> wrote:
>> Hey all,
>>
>> Apologies if this is the wrong list to post to -- I couldn't find a
>> cython-users list...
>>
>> I've been using Cython to speed up instantiation of a Namespace object
>> written in Python: http://paste.lisp.org/display/69989
>>
>> Fundamentally, what I am trying to do is:
>>
>> class Namespace:
>> def __init__(self, **env):
>> global id, store
>> id += 1
>> keys = store[id] = sorted(env)
>> new_env = []
>> for key in keys:
>> obj = env[key]
>> if PyFunction_Check(obj):
>> obj = staticmethod(obj)
>> new_env.append(obj)
>> self.env = new_env
>>
>> The sort() and looping (for key in keys) seems to take up most of the
>> time... how can I do this better so that it takes less time?
>>
>> The Cython version so far is at http://paste.lisp.org/display/69988
>>
>> Please forgive my Cython newbie errors... Thanks!
>>
>> --
>> love, tav
>>
>> plex:espians/tav | tav at espians.com | +44 (0) 7809 569 369
>>
>
>
>
> --
> love, tav
>
> plex:espians/tav | tav at espians.com | +44 (0) 7809 569 369
> _______________________________________________
> Cython-dev mailing list
> Cython-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/cython-dev
>
More information about the Cython-dev
mailing list