#9885: slow coercion from integer mod ring to integer ring
-------------------------+-------------------------------------------------
Reporter: | Owner: tbd
dmharvey | Status: needs_review
Type: | Milestone:
defect | Resolution:
Priority: major | Merged in:
Component: | Reviewers:
performance | Work issues:
Keywords: | Commit:
Authors: Nils | c04c8b5cd99d9614d52dc65df8bb1b07a497ff5a
Bruin | Stopgaps:
Report Upstream: N/A |
Branch: |
u/nbruin/9885 |
Dependencies: |
-------------------------+-------------------------------------------------
Comment (by nbruin):
It looks like you changed more branches (for the better, I hope). You use
a try/except where I use a getattr. I suspect it's better to go with the
getattr for the following reasons:
- The try/except is now also guarding errors that may arise during the
execution of the `_integer_` method, not just the ones that arise in
looking up the attribute. That could mask genuine errors and cause this
method to execute follow-up code when really there is an `_integer_`
method available.
- While try/except is fast to execute when no error is raised, it does
incur a large penalty when the attribute is not found (where
`getattr(x,"_integer_",None)` should return `None` with little penalty).
So I expect your code is slower for branches that come below the
`x._integer_` branch.
I'd recommend adopting the `getattr` solution and otherwise sticking with
your branch.
I've checked and cython produces an inline function for `getattr` that
calls `PyObject_GetAttr` and then catches the exception at a rather low
level. So perhaps the difference isn't that big. I'm more surprised that
cython doesn't seem to specialize these methods to
`PyObject_GetAttrString`, so that it can avoid constructing a python
string object for the attribute name.
Anyway, the possibility for catching extraneous errors with guarding too
much with try/except is I think the strongest argument.
--
Ticket URL: <http://trac.sagemath.org/ticket/9885#comment:6>
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.
For more options, visit https://groups.google.com/d/optout.