Hi Willian, hi Jason

> On 03/25/2010 08:49 PM, William Stein wrote:
>> I was trying to understand why certain modular symbols code was too
>> slow, and ran across a method that looked like this (in
>> modular/modsym/element.py):
>>
[...]
>>
>> Of course, on multiple calls, the above is slow, because the
>> __modular_symbols cache never gets set.
>> So I though, ah ha!, this is a great example where I should use
>> @cached_method, now that we have it.
>> So I tried that, but doing
>>
>>   timeit('...')
>>
>> showed that it still took about 20microsend/call to call the above function.
>> Replacing @cached_method with the try/except as above, but actually
>> settin gself.__modular_symbols correctly resulted in the speedup I
>> wanted (e.g., each call takes a few hundred nanoseconds).

I'm very sorry to says that Nicolas and I are well aware of this problem since
a long time. We have been cursing this a lot more than once. We have been lazy
not at least putting a ticket on track... Many apologies for this.

>> MORAL: If you care about speed, don't use the cached_method decorator
>> yet.   It entails massive overheard.

-1 for not using cached method:

Througout sage library there are a dozen of different looking implementations
for caching some computation. That's a lot of unnecessary code which is very
likely to cause problems upon pickling unpickling (should we pickle or drop
the cache), and even more renders nearly impossible to consistently clear the
cache. I'm strongly in favor of standardization.

+10 for optimizing it.

> See #8611 for the start of a patch which speeds up cached_function by about 
> 30x in your case (no arguments), and @cached_method by about 3x. The ticket 
> has before/after timing information.
>
> I think someone more familiar with Python method decorators (in particular, 
> when you have an instance, etc.) could probably speed up the @cached_method 
> a lot more.  For example, inst.__dict__.setdefault gets called on every 
> call right now.
>
> @cached_method still isn't nearly as fast as a simple cache like what you 
> have above (see the ticket for details), but it's a start.

Some comments:

- The simple and critical cases (eg: no argument) can be even more optimized
at the *creation* of the cached_method objects by looking through
introspection to the function if it has extra argument or not, *arg and
**option or not. Depending on this, different classes can be used which by
pass ArgumentFixer when this is possible.

- This code needs clearly to be Cython. I'm currently learning it... This has
prevented me (together with free time of course) for solving this issue.

Thanks,

Florent

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

To unsubscribe from this group, send email to 
sage-devel+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.

Reply via email to