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

Comment (by nbruin):

 '''sage/categories/homset.py''':
 {{{
 _cache = TripleDict(53)
 }}}
 I guess this 53 is a tuned parameter. Can you comment on the choice?

 line 214
 {{{
     try:
         H = _cache[key]()
     except KeyError:
         H = None
     if H:
 }}}
 Could it happen that bool(H) is false if H is not None? Perhaps safer to
 test
 `H is not None`? I'm not saying that you should. Just comment please.

 line 247 (same thing)

 line 263
 {{{
     _cache[key] = weakref.ref(H)
 }}}
 Can you clarify the following: The way I read this is that H will not be
 protected against GC (good!), but that `_cache` will be be storing a
 strong(?)
 reference to `key`, meaning that the entry in `_cache` under `key` will
 linger
 with a dead weakref afterwards. Shouldn't there be a callback registered
 here
 with the weakref that contacts `_cache` to remove the `key` entry when `H`
 gets
 collected? It may be that your #715 changes already make `_cache` into
 essentially a
 `WeakKeyDict`, but it seems to me that `_cache` should still have a
 callback
 registered on the `weakref` to `H` as well, to remove the entry if `H`
 gets GCd.

 I haven't done extensive testing myself, but you have and the bot happy,
 so I don't think me running tests would change much.

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