#8611: speed up cached_function and cached_method
---------------------------------------+------------------------------------
   Reporter:  jason                    |       Owner:  tbd          
       Type:  enhancement              |      Status:  needs_review 
   Priority:  major                    |   Milestone:  sage-4.6.1   
  Component:  misc                     |    Keywords:  cached method
     Author:  Jason Grout, Simon King  |    Upstream:  N/A          
   Reviewer:                           |      Merged:               
Work_issues:                           |  
---------------------------------------+------------------------------------

Old description:

> There are a number of inefficiencies in the critical path (i.e., the code
> path when values have already been cached) that are addressed in this
> patch.

New description:

 There are a number of inefficiencies in the critical path (i.e., the code
 path when values have already been cached) that are addressed in this
 patch.

 PS:
 The latest patch does in fact much more: Both the critical and the non-
 critical path are improved, using various tricks.

--

Comment(by SimonKing):

 I forgot to mention another bug fix (that is also doctested). It is about
 the comparison of representations of symmetric groups:
 {{{
 sage: spc = SymmetricGroupRepresentation([3])
 sage: spc.important_info = 'Sage rules'
 sage: spc == SymmetricGroupRepresentation([3]) # this used to return
 False!
 True
 }}}

 The ticket description states that the improvements concern the
 ''critical'' path (i.e., the value is already caught). Here is one more
 comparison, that also shows what happens in the non-critical path.

 Setting:
 {{{
 sage: class A:
 ....:     @cached_method
 ....:     def bar(self,x):
 ....:         return x
 ....:     @cached_in_parent_method
 ....:     def barP(self,x):
 ....:         return x
 ....:     def parent(self):
 ....:         return self
 ....:
 sage: a = A()
 }}}

 Without my patch:
 {{{
 # The non-critical path:
 sage: time for x in range(10^6): b=a.bar(x)
 CPU times: user 24.97 s, sys: 0.16 s, total: 25.13 s
 Wall time: 25.13 s
 sage: time for x in range(10^6): b=a.barP(x)
 CPU times: user 41.03 s, sys: 0.13 s, total: 41.16 s
 Wall time: 41.17 s

 # The critical path (now the values are cached):
 sage: time for x in range(10^6): b=a.bar(x)
 CPU times: user 16.45 s, sys: 0.02 s, total: 16.47 s
 Wall time: 16.47 s
 sage: time for x in range(10^6): b=a.barP(x)
 CPU times: user 20.47 s, sys: 0.02 s, total: 20.50 s
 Wall time: 20.50 s
 }}}

 With my patch:
 {{{
 # The non-critical path:
 sage: time for x in range(10^6): b=a.bar(x)
 CPU times: user 11.40 s, sys: 0.08 s, total: 11.48 s
 Wall time: 11.48 s
 sage: time for x in range(10^6): b=a.barP(x)
 CPU times: user 27.89 s, sys: 0.12 s, total: 28.01 s
 Wall time: 28.02 s

 # The critical path (now the values are cached):
 sage: time for x in range(10^6): b=a.bar(x)
 CPU times: user 3.09 s, sys: 0.01 s, total: 3.10 s
 Wall time: 3.10 s
 sage: time for x in range(10^6): b=a.barP(x)
 CPU times: user 5.25 s, sys: 0.02 s, total: 5.26 s
 Wall time: 5.26 s
 }}}

 Hence, the patch improves all cases.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/8611#comment:10>
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