#12313: Fix yet another memory leak caused by caching of coercion data
--------------------------------------------------------+-------------------
Reporter: SimonKing | Owner:
Type: defect | Status:
positive_review
Priority: major | Milestone:
sage-5.8
Component: memleak | Resolution:
Keywords: coercion weak dictionary | Work issues:
Report Upstream: N/A | Reviewers: Simon
King, Jean-Pierre Flori, John Perry, Nils Bruin
Authors: Simon King, Jean-Pierre Flori | Merged in:
Dependencies: #715, #11521, #12215, #13746, #13378 | Stopgaps:
--------------------------------------------------------+-------------------
Comment (by SimonKing):
Together with #13387, one gets
{{{
sage: M=sage.structure.coerce_dict.MonoDict(23)
sage: R = ZZ['x','y','z']
sage: M[R]=1
sage: D={R:1}
sage: timeit("_=M[R]", number=10^6)
1000000 loops, best of 3: 204 ns per loop
sage: timeit("_=D[R]", number=10^6)
1000000 loops, best of 3: 361 ns per loop
sage: D[ZZ]=2
sage: M[ZZ]=2
sage: timeit("_=M[R]", number=10^6)
1000000 loops, best of 3: 204 ns per loop
sage: timeit("_=D[R]", number=10^6)
1000000 loops, best of 3: 359 ns per loop
sage: timeit("_=M[ZZ]", number=10^6)
1000000 loops, best of 3: 206 ns per loop
sage: timeit("_=D[ZZ]", number=10^6)
1000000 loops, best of 3: 98.4 ns per loop
}}}
Hence, it becomes faster, but a Python dictionary is still faster if
"easy" targets such as ZZ are involved.
Indeed, ZZ is very quick at basic operations:
{{{
sage: timeit("hash(ZZ)", number=10^6)
1000000 loops, best of 3: 103 ns per loop
sage: timeit("id(ZZ)", number=10^6)
1000000 loops, best of 3: 102 ns per loop
sage: timeit("hash(R)", number=10^6)
1000000 loops, best of 3: 329 ns per loop
}}}
Hence, the hash of ZZ (used in dict) is as fast as id (used in
`MonoDict`). No surprise that it is ''that'' fast.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12313#comment:303>
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.