#13589: Controlling C3 to solve once for all the Method Resolution Order issues 
for
category classes
----------------------------------------------------------+-----------------
       Reporter:  nthiery                                 |         Owner:  
nthiery                   
           Type:  defect                                  |        Status:  
needs_review              
       Priority:  major                                   |     Milestone:  
sage-5.11                 
      Component:  categories                              |    Resolution:      
                      
       Keywords:  method resolution order, C3             |   Work issues:      
                      
Report Upstream:  N/A                                     |     Reviewers:  
Simon King, Florent Hivert
        Authors:  Nicolas M. ThiƩry                       |     Merged in:      
                      
   Dependencies:  #12894, #12876, #11935, #12895, #10193  |      Stopgaps:      
                      
----------------------------------------------------------+-----------------

Comment (by SimonKing):

 Something findings:

 - C3_sorted_merge was called 121 times with the current patch during
 startup.
 - C3_sorted_merge is called on different Groupoids, which should not
 happen, because all groupoids have the same super categories. Solution:
 Make it `CategoryWithParameters`. Then, C3_sorted_merge is only called 93
 times during startup.
 - There are some optimizations possible in C3_sorted_merge:

 {{{
 sage: L1 = Fields().all_super_categories()
 sage: L2 = Algebras(QQ).all_super_categories()
 sage: cython("""
 def test1(list L):
     cdef list out = L[::-1]
 def test2(list L):
     cdef list out = list(reversed(L))
 """)
 ....:
 sage: %timeit test1(L1)
 1000000 loops, best of 3: 541 ns per loop
 sage: %timeit test2(L1)
 100000 loops, best of 3: 2.25 us per loop
 }}}
 and
 {{{
 sage: cython("""
 ....: def test1(list L):
 ....:     cdef set S = set(x for x in L)
 ....: def test2(list L):
 ....:     cdef set S = set([x for x in L])
 ....: """)
 ....:
 sage: %timeit test1(L1)
 100000 loops, best of 3: 3.91 us per loop
 sage: %timeit test2(L1)
 100000 loops, best of 3: 3.99 us per loop
 sage: %timeit test1(L1)
 100000 loops, best of 3: 3.89 us per loop
 sage: %timeit test1(L1)
 100000 loops, best of 3: 3.89 us per loop
 sage: %timeit test2(L1)
 100000 loops, best of 3: 4.06 us per loop
 }}}

 In both examples above, test2 is what is currently done in
 C3_sorted_merge, and test1 is apparently what ''should'' be done. I am
 preparing a patch now.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13589#comment:45>
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.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to