#715: Parents probably not reclaimed due to too much caching
--------------------------------+-------------------------------------------
   Reporter:  robertwb          |          Owner:  somebody           
       Type:  defect            |         Status:  needs_work         
   Priority:  major             |      Milestone:  sage-4.8           
  Component:  coercion          |       Keywords:  weak cache coercion
Work_issues:  Get some timings  |       Upstream:  N/A                
   Reviewer:                    |         Author:  Simon King         
     Merged:                    |   Dependencies:  #9138, #11900      
--------------------------------+-------------------------------------------

Comment(by SimonKing):

 Perhaps as follows: We currently have one ensemble of buckets. Instead, we
 could have two ensembles, say, `self.keys` and `self.refs`. Each bucket in
 both ensembles is a list of length `3*n`. Let `X,Y,Z` be  key, let h be
 the hash of that triple and V the value associated with `X,Y,Z`.

 Then, one could store `X,Y,Z` as `self.keys[h][i:i+3]`, with artificially
 decrementing the reference count for X and Y (but not for Z, which usually
 is True, False, None, operator.mul and so on), as suggested by Volker. And
 `self.refs[h][i:i+3]` would be formed by a weak reference to X, a weak
 reference to Y, and V. The two weak references have a callback function,
 that tries to find a reference `self.refs[h][j]` when it became invalid,
 and would delete the corresponding triple both in `self.refs[h]` and in
 `self.keys[h]`.

 Two weak references with callback function pointing to the same object are
 distinct (they are only the same if they don't have a callback function).
 Hence, each reference occurs in the `TripleDict` exactly once. Hence, it
 makes sense to store the hash value of the ''triple'' `X,Y,Z` as
 additional data both in the reference to X and to Y - which is possible
 with `weakref.KeyedRef`. In that way, deleting an entry when a reference
 became invalid would be much faster as with my current patch, since it is
 not needed to search in ''all'' buckets.

 I will try it tomorrow.

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