#8611: speed up cached_function and cached_method
---------------------------+------------------------------------------------
   Reporter:  jason        |       Owner:  tbd     
       Type:  enhancement  |      Status:  new     
   Priority:  major        |   Milestone:  sage-4.4
  Component:  misc         |    Keywords:          
     Author:  Jason Grout  |    Upstream:  N/A     
   Reviewer:               |      Merged:          
Work_issues:               |  
---------------------------+------------------------------------------------

Comment(by davidloeffler):

 Might it not be better for @cached_method to store its cache as an
 attribute of the instance object, rather than having a single cache which
 stores the values for all instances of that class?

 E.g. the following code works for methods with no arguments:

 {{{
 def fast_cached_method(func):
     def fast_func(some_instance):
         try:
             return getattr(some_instance, '_cache_' + func.__name__)
         except AttributeError:
             result = func(some_instance)
             foo_instance.__dict__['_cache_' + func.__name__] = result
             return result
     return fast_func
 }}}

 I tested this and it's only about 1.5 times slower than doing the caching
 "by hand", while your speeded-up version above is still about 40 times
 slower.

 David

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/8611#comment:4>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to