#20686: Optimize method lookup from the categories for instances of Cython
classes
----------------------------------+------------------------
Reporter: nthiery | Owner:
Type: enhancement | Status: new
Priority: major | Milestone: sage-7.3
Component: categories | Resolution:
Keywords: | Merged in:
Authors: Jeroen Demeyer | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
Dependencies: | Stopgaps:
----------------------------------+------------------------
Changes (by {'newvalue': u'Jeroen Demeyer', 'oldvalue': ''}):
* author: => Jeroen Demeyer
Old description:
> For instances of Cython classes, the inheritance from categories is
> emulated by a manual lookup in
> `sage.structure.element.Element.__getattr__`. This lookup is about 10
> times slower than a normal method lookup::
>
> {{{
> sage: def foo(self): return
> sage: Sets().element_class.foo = foo
>
> sage: def g(x):
> ....: for i in range(1000):
> ....: x.foo()
>
> sage: x = Semigroups().example().an_element()
> sage: %timeit g(x)
> 10000 loops, best of 3: 115 µs per loop
>
> sage: x = 1
> sage: %timeit g(x)
> 1000 loops, best of 3: 1.18 ms per loop
> }}}
>
> So there should be room for optimization (or using a different
> approach for emulating this inheritance).
>
> First step: profiling ...
New description:
For instances of Cython classes, the inheritance from categories is
emulated by a manual lookup in
`sage.structure.element.Element.__getattr__`. This lookup is about 10
times slower than a normal method lookup::
{{{
sage: def foo(self): return
sage: Sets().element_class.foo = foo
sage: def g(x):
....: for i in range(1000):
....: x.foo()
sage: x = Semigroups().example().an_element()
sage: %timeit g(x)
10000 loops, best of 3: 115 µs per loop
sage: x = 1
sage: %timeit g(x)
1000 loops, best of 3: 1.18 ms per loop
}}}
So there should be room for optimization (or using a different
approach for emulating this inheritance).
Besides this, we should not pick up special attributes from `type`, there
is no point in returning `type.__name__` here:
{{{
sage: getattr_from_other_class(1, type, "__name__")
'type'
}}}
--
--
Ticket URL: <http://trac.sagemath.org/ticket/20686#comment:4>
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 https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.