#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):
OK, patch is updated.
Here are timings for key length 1:
{{{
sage: from sage.structure.idkey_dict import IdKeyDict
sage: from sage.structure.coerce_dict import MonoDict
sage: import weakref
sage: I = IdKeyDict(1,53, threshold=0.7)
sage: M = MonoDict(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
....: M[K] = i
....: I[K] = i
....:
sage: K in W
True
sage: K in M
True
sage: K in I
True
sage: K2 in W
False
sage: K2 in M
False
sage: K2 in I
False
sage: %timeit K in W
625 loops, best of 3: 56 µs per loop
sage: %timeit K in M
625 loops, best of 3: 550 ns per loop
sage: %timeit K in I
625 loops, best of 3: 571 ns per loop
sage: %timeit K2 in W
625 loops, best of 3: 2.46 µs per loop
sage: %timeit K2 in M
625 loops, best of 3: 1.55 µs per loop
sage: %timeit K2 in I
625 loops, best of 3: 387 ns per loop
sage: W[K]
1228
sage: M[K]
1228
sage: I[K]
1228
sage: %timeit W[K]
625 loops, best of 3: 55.1 µs per loop
sage: %timeit M[K]
625 loops, best of 3: 616 ns per loop
sage: %timeit I[K]
625 loops, best of 3: 523 ns per loop
}}}
and concerning garbage collection
{{{
sage: del L
sage: import gc
sage: gc.collect()
321790
sage: len(W)
1
sage: len(M)
1
sage: len(I)
1
sage: list(I.iteritems())
[((194308608, <weakref at 0xbbd9110; to
'sage.rings.polynomial.multi_polynomial_libsingular' at 0xb94ea00
(JoinCategory.parent_class)>), 1228)]
}}}
Hence, the timings of the general implementation (general key length) are
competitive. What do you think about it? Of course, one would need to add
doctests.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12313#comment:170>
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.