#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 nbruin):
Replying to [comment:302 SimonKing]:
> {{{
> ...
> 1000000 loops, best of 3: 348 ns per loop
> sage: D[ZZ]=2
> sage: M[ZZ]=2
> sage: timeit("_=M[R]", number=10^6)
> 1000000 loops, best of 3: 307 ns per loop
> sage: timeit("_=D[R]", number=10^6)
> 1000000 loops, best of 3: 351 ns per loop
> }}}
Those timing lines don't relate to `ZZ`. Since your other timings are in
line with what I found doing exactly the same example above, you'd
probably also see that lookup of `ZZ` in D is about 3 times as fast as it
is in `M`.
It's interesting to see that many rings in sage are so much slower (unique
parents should always be able to use `id` for equality and for their hash,
right?)
Anyway, going from a strong dict to a weak key dict is *supposed* to be a
little slower, so this is not an issue. We'll just have to live with it.
A more serious issue is the limited use of `MonoDict` in this case.
Essentially, this `MonoDict` only has an effect for the cases where we
cache that there is NO coercion: In the other cases, we have an entry
{{{
M[Domain] = coercion map from Domain to This Parent
}}}
i.e., the value in the weak key dict will hold a strong reference to the
key. A self-quotation from [https://groups.google.com/group/sage-
flame/msg/51ee8af7cc2cac11?hl=en sage-flame] seems appropriate.
I think this is an fundamental problem and just one people will have to
hold in mind: Coercing TO something will make the object you coerce FROM
stay in memory for as long as the target is there. It's just a little
disappointing that all this effort for a weak key dict is only going to
make a difference for the entries that store `None` as a value. Oh well.
That does happen a lot. AND we are getting speed increases in many cases!
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12313#comment:304>
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.