#10467: Improve lookup of private attributes
---------------------------+------------------------------------------------
Reporter: SimonKing | Owner: tbd
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-4.6.1
Component: performance | Keywords: private attribute lookup
Author: Simon King | Upstream: N/A
Reviewer: | Merged:
Work_issues: |
---------------------------+------------------------------------------------
Comment(by SimonKing):
I found yet another way to speed things up!
Typically, in Python one requests an attribute and catches an
`AttributeError` (this is also done in Python's `hasattr`, IIRC). That
happens very often during computations. Hence, it is very important that
''raising'' the error happens quickly.
The `__getattr__` methods of sage.structure.parent.Parent and
sage.structure.element.Element call a Python method
sage.structure.parent.raise_attribute_error, that first creates the error
message and then raises the `AttributeError`. Interpreted Python is too
slow for that purpose!
Therefore I updated my patch (will post it in a few minutes). Trick:
Instead of
{{{
def raise_attribute_error(self, name)
}}}
it is now
{{{
cdef inline raise_attribute_error(self,name)
}}}
The effect of this little trick, compared with the benchmarks above, is:
(1) Saves almost 20% compared with the old patch, and more than 50%
compared with unpatched Sage:
{{{
sage: P.<x> = QQ[]
sage: timeit('a=repr(x)')
625 loops, best of 3: 33.8 µs per loop
}}}
(2) Saves almost 10% compared with the old patch and almost 50% compared
with unpatched Sage:
{{{
sage: R.<x,y> = InfinitePolynomialRing(QQ)
sage: I = R.ideal([x[1]^2+y[2]*y[3], x[2]*y[1]*x[3]-y[1]*y[2]])
sage: %time I.groebner_basis()
CPU times: user 13.30 s, sys: 0.02 s, total: 13.32 s
Wall time: 13.38 s
[y_2*y_1^3 + y_2*y_1^2, y_2^2*y_1 - y_2*y_1^2, y_3*y_1 - y_2*y_1,
x_1*y_2*y_1^2 + x_1*y_2*y_1, x_1^2 + y_2*y_1, x_2*y_2*y_1 - x_1*y_2*y_1,
x_2*x_1*y_3 - y_2*y_1, x_3*y_2*y_1 - x_1*y_2*y_1, x_3*x_1*y_2 - y_2*y_1,
x_3*x_2*y_1 - y_2*y_1]
}}}
(3) No significant difference in the third benchmark:
{{{
sage: timeit('a=QQ.summation',number=50000)
50000 loops, best of 3: 526 ns per loop
sage: timeit('a=QQ.summation',number=50000)
50000 loops, best of 3: 524 ns per loop
sage: timeit('a=QQ.summation',number=50000)
50000 loops, best of 3: 527 ns per loop
}}}
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10467#comment:3>
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.