#12313: Fix yet another memory leak caused by caching of coercion data
--------------------------------------------------------+-------------------
       Reporter:  SimonKing                             |         Owner:        
                                               
           Type:  defect                                |        Status:  
positive_review                                      
       Priority:  major                                 |     Milestone:  
sage-5.8                                             
      Component:  memleak                               |    Resolution:        
                                               
       Keywords:  coercion weak dictionary              |   Work issues:        
                                               
Report Upstream:  N/A                                   |     Reviewers:  Simon 
King, Jean-Pierre Flori, John Perry, Nils Bruin
        Authors:  Simon King, Jean-Pierre Flori         |     Merged in:        
                                               
   Dependencies:  #715, #11521, #12215, #13746, #13378  |      Stopgaps:        
                                               
--------------------------------------------------------+-------------------

Comment (by SimonKing):

 Replying to [comment:304 nbruin]:
 > Replying to [comment:302 SimonKing]:
 > > {{{
 > > ...
 > > 1000000 loops, best of 3: 348 ns per loop
 > > sage: D[ZZ]=2
 > > sage: M[ZZ]=2
 > > sage: timeit("_=M[R]", number=10^6)
 > > 1000000 loops, best of 3: 307 ns per loop
 > > sage: timeit("_=D[R]", number=10^6)
 > > 1000000 loops, best of 3: 351 ns per loop
 > > }}}
 > Those timing lines don't relate to `ZZ`.

 I didn't claim they are. This was in order to show that under some not so
 unlikely circumstances `MonoDict` is faster than a usual dict-

 > Since your other timings are in line with what I found doing exactly the
 same example above, you'd probably also see that lookup of `ZZ` in D is
 about 3 times as fast as it is in `M`.

 Yep, I posted these timings as well, didn't I?

 > A more serious issue is the limited use of `MonoDict` in this case.
 Essentially, this `MonoDict` only has an effect for the cases where we
 cache that there is NO coercion: In the other cases, we have an entry
 > {{{
 > M[Domain] = coercion map from Domain to This Parent
 > }}}
 > i.e., the value in the weak key dict will hold a strong reference to the
 key.

 I am not so sure, because I think this was one of the memleaks I
 explicitly addressed somewhere. But since my Sage install currently is
 ''without'' #12313, I need to recompile now -- which takes an eternity. I
 hope I'll be able to show you an example.

 Anyway.

 Here is a timing that shows that this patch has a bad effect ''both'' on
 looking up the coercion map ''and'' applying the coercion:

 Without #12313
 {{{
 sage: timeit("phi=QQ.coerce_map_from(ZZ)", number=10^6)
 1000000 loops, best of 3: 503 ns per loop
 sage: phi=QQ.coerce_map_from(ZZ)
 sage: x = -20
 sage: timeit("phi(x)", number=10^6)
 1000000 loops, best of 3: 563 ns per loop
 }}}

 With #12313:
 {{{
 sage: timeit("phi=QQ.coerce_map_from(ZZ)", number=10^6)
 1000000 loops, best of 3: 738 ns per loop
 sage: phi=QQ.coerce_map_from(ZZ)
 sage: x = -20
 sage: timeit("phi(x)", number=10^6)
 1000000 loops, best of 3: 616 ns per loop
 }}}

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