#12313: Fix yet another memory leak caused by caching of coercion data
-------------------------------------------------+--------------------------
       Reporter:  SimonKing                      |         Owner:  rlm         
           Type:  defect                         |        Status:  needs_review
       Priority:  major                          |     Milestone:  sage-5.0    
      Component:  memleak                        |    Resolution:              
       Keywords:  coercion weak dictionary       |   Work issues:              
Report Upstream:  N/A                            |     Reviewers:  Simon King  
        Authors:  Simon King, Jean-Pierre Flori  |     Merged in:              
   Dependencies:  #715, #11521, #11599           |      Stopgaps:              
-------------------------------------------------+--------------------------
Changes (by SimonKing):

  * reviewer:  => Simon King


Old description:

> The following could not be fixed in #715:
>
> {{{
> sage: K = GF(1<<55,'t')
> sage: for i in range(50):
> ....:     a = K.random_element()
> ....:     E = EllipticCurve(j=a)
> ....:     b = K.has_coerce_map_from(E)
> ....:
> sage: import gc
> sage: gc.collect()
> 0
> }}}
> The problem is that any parent has a dictionary that stores any coerce
> map (and a different dictionary for conversion maps) ending at this
> parent. The keys are given by the domains of the maps. So, in the example
> above, the field `K` has an attribute that is a dictionary whose keys are
> the different elliptic curves.
>
> In coercion, it is usually best to compare parents not by equality but by
> identity. Therefore, I suggest to implement a container called `MonoDict`
> that works similar to the new weak `TripleDict` (see #715), but takes a
> single item as a key.
>
> First tests show that one can actually gain a lot of speed: `MonoDict`
> can access its items much faster than a usual dictionary.
>
> __Apply__
>
>  * [attachment:trac_12313-mono_dict-take2.patch]
>  * [attachment:trac_12313-rebase_11599-take2.patch]
>  * [attachment:trac_12313-cparent-take2.patch]
>  * [attachment:trac_12313-reviewer-take2.patch]
>  * [attachment:trac_12313-size_t-take2.patch]

New description:

 The following could not be fixed in #715:

 {{{
 sage: K = GF(1<<55,'t')
 sage: for i in range(50):
 ....:     a = K.random_element()
 ....:     E = EllipticCurve(j=a)
 ....:     b = K.has_coerce_map_from(E)
 ....:
 sage: import gc
 sage: gc.collect()
 0
 }}}
 The problem is that any parent has a dictionary that stores any coerce map
 (and a different dictionary for conversion maps) ending at this parent.
 The keys are given by the domains of the maps. So, in the example above,
 the field `K` has an attribute that is a dictionary whose keys are the
 different elliptic curves.

 In coercion, it is usually best to compare parents not by equality but by
 identity. Therefore, I suggest to implement a container called `MonoDict`
 that works similar to the new weak `TripleDict` (see #715), but takes a
 single item as a key.

 First tests show that one can actually gain a lot of speed: `MonoDict` can
 access its items much faster than a usual dictionary.

 __Apply__

  * [attachment:trac_12313-mono_dict-combined.patch]

--

Comment:

 I have attached a combined patch, that is obtained by folding all patches
 that have previously to be applied. In particular, it contains the fix
 "use size_t instead of Py_ssize_t".

 For me (64 bit), all tests pass (thus, positive review from me for the
 parts of code written by Jean-Pierre), but we should wait for Jean-
 Pierre's results on 32 bit.

 For the patchbot:

 Apply trac_12313-mono_dict-combined.patch

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