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

Comment (by SimonKing):

 Replying to [comment:163 nbruin]:
 > Observation: The test above is entirely unrepresentative because there
 is no resizing whatsoever (default `threshold=0` leads to no resizing). So
 the test above was just using `53` buckets, meaning it was mainly doing
 linear search! Impressive how fast that is, of course, but more
 representative is (`2/3` is the threshold ratio that Python's `dict` uses
 by default)

 Good point! By your comment, I have now threshold=0.7 as default in my
 experimental code.

 > That's why `MonoDict` won for membership. It was using a properly
 calibrated `dict` versus a linear search in `MonoDictNoRefCache`.

 Yes, that would explain it.

 > Concerning `TupleDict`: Sure we can implement it but if our only use
 cases are `MonoDict` and `TripleDict` anyway, we're better off with the
 unrolled loops.

 Last night I already wrote experimental code (calling the thing
 "`IdKeyDict`", because the keys are compared by identity). I am now doing
 some tests - perhaps we are lucky and it is fast...

 `MonoDict` and `TripleDict` are the only use cases ''yet''. Until not so
 long time ago, `TripleDict` has been the only use case. One could imagine
 that an `IdKeyDict` being useful for a weak_cached_function, as in #12215:
 If you have a function with a fixed list of arguments (hence, no *args and
 **keys), and if you are happy to compare the arguments by identity,
 `IdKeyDict` may be exactly the thing you want.

 Plus, one avoids code duplication. And aren't modern compilers intelligent
 enough to do some loop unrolling automatically?

 Anyway, since I already wrote code, I'll first test the performance,
 rather than immediately dropping the idea of unifying `MonoDict` and
 `TripleDict`.

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