#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):
I just added an experimental patch [attachment:idkey_dict] that implements
what I proposed in my previous posts. The timings seem very appealing:
{{{
sage: from sage.structure.idkey_dict import IdKeyDict
sage: from sage.structure.coerce_dict import TripleDict
sage: import weakref
sage: I = IdKeyDict(3,53, threshold=0.7)
sage: T = TripleDict(53, threshold=0.7)
sage: W = weakref.WeakKeyDictionary()
sage: L = []
sage: for p in prime_range(10000):
....: L.append(GF(p)['x','y'])
....:
sage: K = GF(97)['x','y']
sage: K2 = GF(next_prime(p))['x','y']
sage: for i,K in enumerate(L):
....: W[K] = i
....: I[K,K,True] = i
....: T[K,K,True] = i
....:
sage: (K,K,True) in I
True
sage: (K,K,True) in T
True
sage: K in W
True
sage: %timeit (K,K,True) in I
625 loops, best of 3: 1.31 µs per loop
sage: %timeit (K,K,True) in T
625 loops, best of 3: 2.14 µs per loop
sage: %timeit K in W
625 loops, best of 3: 56.4 µs per loop
sage: (K2,K,True) in I
False
sage: (K2,K,True) in T
False
sage: K2 in W
False
sage: %timeit (K2,K,True) in I
625 loops, best of 3: 523 ns per loop
sage: %timeit (K2,K,True) in T
625 loops, best of 3: 2.07 µs per loop
sage: %timeit K2 in W
625 loops, best of 3: 2.4 µs per loop
sage: I[K,K,True]
1228
sage: T[K,K,True]
1228
sage: W[K]
1228
sage: %timeit I[K,K,True]
625 loops, best of 3: 1.24 µs per loop
sage: %timeit T[K,K,True]
625 loops, best of 3: 2.19 µs per loop
sage: %timeit W[K]
625 loops, best of 3: 55.6 µs per loop
}}}
Hence, the ''general'' `IdKeyDict`, that implements any fixed key length,
already beats `TripleDict`. But not all is good: When I tried to compare
with `MonoDict`, I got a segfault in `__setitem__`
Back to the drawing board, then...
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12313#comment:169>
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.