#11521: Use weak references to cache homsets
--------------------------------------------------+-------------------------
       Reporter:  jpflori                         |         Owner:  robertwb    
                 
           Type:  defect                          |        Status:  
positive_review              
       Priority:  major                           |     Milestone:  sage-5.5    
                 
      Component:  coercion                        |    Resolution:              
                 
       Keywords:  sd35                            |   Work issues:              
                 
Report Upstream:  N/A                             |     Reviewers:  Jean-Pierre 
Flori, Nils Bruin
        Authors:  Simon King                      |     Merged in:              
                 
   Dependencies:  #12969; to be merged with #715  |      Stopgaps:              
                 
--------------------------------------------------+-------------------------
Changes (by nbruin):

  * status:  needs_work => positive_review


Old description:

> Originally, this ticket was about the following memory leak when
> computing with elliptic curves:
>
> {{{
> sage: K = GF(1<<55,'t')
> sage: a = K.random_element()
> sage: while 1:
> ....:     E = EllipticCurve(j=a); P = E.random_point(); 2*P;
> }}}
> This example is in fact solved by #715. However, while working on that
> ticket, another leak has been found, namely
>
> {{{
> sage: for p in prime_range(10^5):
> ....:     K = GF(p)
> ....:     a = K(0)
> ....:
> sage: import gc
> sage: gc.collect()
> 0
> }}}
> So, I suggest to start with #715 and solve the second memory leak on top
> of it. It seems that a strong cache for homsets is to blame. I suggest to
> use the weak `TripleDict` instead, which were introduced in #715.
>
> '''To be merged with #715 and #13447'''. Apply
>
> * the patches from #715
> * [attachment:trac_11521_homset_weakcache_combined.patch]
> * [attachment:trac_11521_callback.patch]

New description:

 Originally, this ticket was about the following memory leak when computing
 with elliptic curves:

 {{{
 sage: K = GF(1<<55,'t')
 sage: a = K.random_element()
 sage: while 1:
 ....:     E = EllipticCurve(j=a); P = E.random_point(); 2*P;
 }}}
 This example is in fact solved by #715. However, while working on that
 ticket, another leak has been found, namely

 {{{
 sage: for p in prime_range(10^5):
 ....:     K = GF(p)
 ....:     a = K(0)
 ....:
 sage: import gc
 sage: gc.collect()
 0
 }}}
 So, I suggest to start with #715 and solve the second memory leak on top
 of it. It seems that a strong cache for homsets is to blame. I suggest to
 use the weak `TripleDict` instead, which were introduced in #715.

 '''To be merged with #715 and #13447'''. Apply

 * the patches from #715
 * [attachment:trac_11521_homset_weakcache_combined.patch]
 * [attachment:trac_11521_callback.patch]
 * [attachment:trac_11521_doctestfix.patch]

--

Comment:

 OK, I've adapted two doctests to reflect that polynomial rings still are
 not garbage collected. Furthermore, I backported two changes from #13447:

  - A change to a doctest for modular forms spaces, which depended on
 previously cached computation. Since these things do get collected now,
 the caching was lost. The rewrite forces recomputation, so the dependence
 on things not getting deleted is removed

  - The ignored `AttributeError` (which doesn't cause a doctest failure, by
 the way. The warning is only visible because it happened near a doctest
 that failed for another reason). Since we found where this ignore was
 happening anyway
 [http://trac.sagemath.org/sage_trac/ticket/13447#comment:30] we might as
 well fix it now. It's a side-effect of things getting collected, but the
 change itself doesn't depend on the proper refcounting details that #13447
 itself is hanging on.

 All doctests pass for me with this, so back to positive review.

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