#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 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):
{{{
M = MonoDict(53,threshold=2/3)
N = MonoDictNoRefCache(53,threshold=2/3)
...
sage: sage: %timeit K in W
625 loops, best of 3: 1.06 µs per loop
sage: sage: %timeit K in M
625 loops, best of 3: 169 ns per loop
sage: sage: %timeit K in N
625 loops, best of 3: 128 ns per loop
sage: sage:
sage: sage: %timeit K2 in W
625 loops, best of 3: 800 ns per loop
sage: sage: %timeit K2 in M
625 loops, best of 3: 426 ns per loop
sage: sage: %timeit K2 in N
625 loops, best of 3: 67.1 ns per loop
sage: sage:
sage: sage: %timeit a = W[K]
625 loops, best of 3: 941 ns per loop
sage: sage: %timeit a = M[K]
625 loops, best of 3: 169 ns per loop
sage: sage: %timeit a = N[K]
625 loops, best of 3: 122 ns per loop
}}}
That's why `MonoDict` won for membership. It was using a properly
calibrated `dict` versus a linear search in `MonoDictNoRefCache`. I think
our design is clear now.
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.
Somewhere in the next few days I'll prepare a patch for #715 to move
`TripleDict` to this design and then put a patch on #12313 for `MonoDict`,
if that's OK with people. In the mean time, comments on design welcome.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12313#comment:163>
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.