#11521: Use weak references to cache homsets
--------------------------------------------------+-------------------------
       Reporter:  jpflori                         |         Owner:  robertwb    
                 
           Type:  defect                          |        Status:  
positive_review              
       Priority:  major                           |     Milestone:  sage-5.4    
                 
      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


Comment:

 OK, I retract my concern for ''this patch''. No coercions are stored here!
 In particular, any `H` occurring here is a homset, not a map. This cache
 is simply ensuring that `Hom(X,Y)` is unique. So indeed, this cache should
 not be preventing `H` from being collected. The `KeyedRef` is entirely in
 place.

 I `was` looking at #12313 when this struck me and I think the discussion
 above has relevance to that case. Once a coercion `h: X -> Y` is
 discovered, a strong reference to `h` is stored in
 `self._coerce_from_hash`. Since `h` stores a strong reference to `X` we
 now have ensured that the life time of `X` is bounded below by the life
 time of `Y`. So the weak caching there only helps for `X` that do not
 coerce into `Y`.

 How eagerly does the system use the `self._convert_from_hash`? It is quite
 likely that even with #12313 in place,
 {{{#!python
 for p in prime_range(1,1000):
     k=GF(p)
     a=k(1)
     b=ZZ(a)
 }}}
 would still leak, due to the conversion `GF(p)->ZZ` being cached on `ZZ`.
 That would make me believe we should probably not cache conversions. There
 are too many of them, so it's too easy to let sage discover enough of them
 that all objects in memory are in one connected component.

 For coercion things are a little brighter because objects with lots of
 inbound arrows (near-universal codomains?) are rarer.

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