#715: Parents probably not reclaimed due to too much caching
--------------------------------+-------------------------------------------
   Reporter:  robertwb          |          Owner:  somebody           
       Type:  defect            |         Status:  needs_review       
   Priority:  major             |      Milestone:  sage-4.8           
  Component:  coercion          |       Keywords:  weak cache coercion
Work_issues:  Get some timings  |       Upstream:  N/A                
   Reviewer:                    |         Author:  Simon King         
     Merged:                    |   Dependencies:  #9138, #11900      
--------------------------------+-------------------------------------------
Changes (by SimonKing):

  * status:  needs_info => needs_review


Comment:

 It is always possible that there is a regression on some hardware, but not
 on all.

 I made an excessive log, i.e., I logged all Python commands. It turns out
 that there are only little differences with or without patch. Hence, I am
 sure that the regression does not come from an excessive garbage
 collection (otherwise, I would have seen that some objects are created
 repeatedly). So, I guess the regression comes from the C-level.

 There is one thing that could make my code too slow: I use weak references
 in my version of `TripleDict` and `TripleDictById`; however, when getting
 dictionary items, I am calling the weak reference, in order to get the
 object that it is pointing to, and compare then. That is slow.

 I was thinking: Perhaps I could manage to use `id(X)` as key of
 `TripleDictById`, rather than a weak reference to `X`. The weak reference
 to `X` could be stored elsewhere.

 Anyway, here is a data point:
 Unpatched (there is only `TripleDict`, no `TripleDictById`):
 {{{
 sage: from sage.structure.coerce_dict import TripleDict
 sage: D = TripleDict(113)
 sage: L = []
 sage: for p in prime_range(10^3):
 ....:     K = GF(p)
 ....:     P = K['x','y']
 ....:     L.append((K,P))
 ....:
 sage: for i,(K,P) in enumerate(L):
 ....:     D[K,P,True] = i
 ....:
 sage: cython("""
 ....: def testD(D, list L):
 ....:     for K,P in L:
 ....:         n = D[K,P,True]
 ....: """)
 sage: %timeit testD(D,L)
 625 loops, best of 3: 30.6 µs per loop
 }}}

 Patched (comparing `TripleDict` and `TripleDictById`):
 {{{
 sage: from sage.structure.coerce_dict import TripleDict, TripleDictById
 sage: D = TripleDict(113)
 sage: E = TripleDictById(113)
 sage: L = []
 sage: for p in prime_range(10^3):
 ....:     K = GF(p)
 ....:     P = K['x','y']
 ....:     L.append((K,P))
 ....:
 sage: for i,(K,P) in enumerate(L):
 ....:     D[K,P,True] = i
 ....:     E[K,P,True] = i
 ....:
 sage: cython("""
 ....: def testD(D, list L):
 ....:     for K,P in L:
 ....:         n = D[K,P,True]
 ....: """)
 sage: %timeit testD(D,L)
 25 loops, best of 3: 21 ms per loop
 sage: %timeit testD(E,L)
 625 loops, best of 3: 61.9 µs per loop
 }}}

 In the applications, I am mainly using `TripleDictById`. Nevertheless, it
 is only half as fast as the old `TripleDict`. So, this is what I have to
 work at!

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