#13387: Improve MonoDict and TripleDict data structures
----------------------------------+-----------------------------------------
Reporter: nbruin | Owner: Nils Bruin
Type: enhancement | Status: needs_review
Priority: major | Milestone:
sage-duplicate/invalid/wontfix
Component: memleak | Resolution:
Keywords: | Work issues:
Report Upstream: N/A | Reviewers:
Authors: Nils Bruin | Merged in:
Dependencies: #11521, #12313 | Stopgaps:
----------------------------------+-----------------------------------------
Comment (by nbruin):
Concerning the timing reported on
[http://trac.sagemath.org/sage_trac/ticket/12313#comment:300 #12313:300],
with the patch here we get
{{{
sage: M=sage.structure.coerce_dict.MonoDict(23)
sage: M[ZZ]=1
sage: %timeit _=M[ZZ]
625 loops, best of 3: 240 ns per loop
}}}
which is an improvement of 91 ns over the 331 ns reported there. Since a
normal dictionary times 110 ns for this operation, and this patch avoids
the internal use of another dictionary lookup in `_refcache`, it seems
like the gain is indeed basically purely the removal of `_refcache`.
We now have
{{{
sage: x=-20
sage: def test():
....: for n in xrange(10**7):
....: _=QQ(x)
....:
sage: sage: time test()
Time: CPU 7.92 s, Wall: 7.95 s
}}}
That is a bit of a gain over `Time: CPU 8.53 s, Wall: 8.57 s` we have
without #13387, but still quite a bit worse than the `Time: CPU 2.97 s,
Wall: 2.98 s` we have prior to #12313. The difference is that the
dictionary that stores the conversion and coercion maps turned into a
weakkeyref dict (`MonoDict`), which is necessarily slower in key lookup
than a normal dict, because there's an extra indirection level in the
keys.
Concerning Jeroen's original report, we now have (#12313 + #13387)
{{{
sage: def test(RR):
....: for d in range(-20,0):
....: if abs(RR(quadratic_L_function__numerical(1, d, 10000) -
quadratic_L_function__exact(1, d))) > 0.001:
....: print "Oops! We have a problem at d = ", d, "
exact = ", RR(quadratic_L_function__exact(1, d)), " numerical = ",
RR(quadratic_L_function__numerical(1, d))
....:
sage: time test(RealField(50))
Time: CPU 1.81 s, Wall: 1.82 s
}}}
versus reference timing
{{{
Time: CPU 1.63 s, Wall: 1.64 s
}}}
To compare, on this machine, the same test with just #12313 takes
{{{
Time: CPU 2.07 s, Wall: 2.08 s
}}}
so the improvements here do significantly reduce the regression originally
reported by Jeroen.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13387#comment:8>
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.