#14214: Cythoned homsets
----------------------------------------------+-----------------------------
       Reporter:  SimonKing                   |         Owner:  tbd             
          
           Type:  enhancement                 |        Status:  needs_work      
          
       Priority:  major                       |     Milestone:  sage-5.9        
          
      Component:  performance                 |    Resolution:                  
          
       Keywords:  Hom, cython, cached method  |   Work issues:  Do not change 
cmp too much
Report Upstream:  N/A                         |     Reviewers:                  
          
        Authors:  Simon King                  |     Merged in:                  
          
   Dependencies:  #14159, #12951, #13184      |      Stopgaps:                  
          
----------------------------------------------+-----------------------------

Comment (by nbruin):

 Oh, OK, but WHERE things are stored may change if the subclass has a
 writeable attribute dictionary, so we have to be a little more careful:
 {{{
 sage: cython("""
 sage: from sage.misc.cachefunc import cached_method
 sage: from sage.structure.parent cimport Parent
 sage: cdef class T(sage.structure.parent.Parent):
 ...       @cached_method
 ...       def C(self):
 ...           return 10
 ...       property B:
 ...           def __get__(self):
 ...               if self.__cached_methods is not None:
 ...                   return self.__cached_methods['C'].cache
 ...               else:
 ...                   return self.C.cache
 ...           def __set__(self,value):
 ...               if self.__cached_methods is not None:
 ...                   self.__cached_methods['C'].cache=value
 ...               else:
 ...                   self.C.cache=value
 ...
 sage: """)
 sage: A=T()
 sage: timeit('A.C()')
 625 loops, best of 3: 389 ns per loop
 sage: timeit('A.B')
 625 loops, best of 3: 201 ns per loop
 sage: class TT(T): pass
 sage: D=TT()
 sage: timeit('D.C()')
 625 loops, best of 3: 198 ns per loop
 sage: timeit('D.B')
 625 loops, best of 3: 209 ns per loop
 sage: D.v=10
 sage: timeit('D.v')
 625 loops, best of 3: 202 ns per loop
 }}}
 and indeed, now we see that a cached method (if possible) inserts things a
 little further down the MRO if possible and hence gets a speed increase.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14214#comment:25>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to