#12808: Optimize ClassCallMetaClass using Cython
--------------------------------------------------+-------------------------
Reporter: hivert | Owner: jason
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-5.0
Component: misc | Resolution:
Keywords: classcall UniqueRepresentation | Work issues:
Report Upstream: N/A | Reviewers:
Authors: Florent Hivert | Merged in:
Dependencies: | Stopgaps:
--------------------------------------------------+-------------------------
Comment (by hivert):
Hi Simon,
> Conclusion: Assigning `sys.modules` to a Python variable brings a speed-
up
> of 1/3, and assigning it to a Cython variable brings a speed-up of 5/6.
So,
> the speed-up obtained from Cython is indeed huge.
Cool ! So my intuition where wrong. This is something I don't feel very
comfortable with Python. When I try to predict which part of the code
should
be optimized I'm too often wrong. I remember being much better at that in
MuPAD. I have the impression that Python is not very predictable, but
maybe
it's just me. I guess I need to optimize more code.
> > Sure ! ClasscallType was for me a step before doing more in depth
change in
> > the Metaclass infrastructure. I was quite scared to do those in depth
change
> > in Sage/Python and feared a lot of hard to debug segfaults.
>
> Fear thee not!
;-)
> > I planned to keep the rest of the metaclass infrastructure
> > for another patch but if you think you cdefing NestedClassMetaclass is
easily
> > done, we can do both at once an thus the need of ClasscallType
vanishes.
>
> Yes, it is easily done - *if* one knows what to cimport. How did you
find out?
They is an example (writen by Robert I think) in Parent. Googling "Cython
subclassing builtin" gives some good examples:
- http://wiki.cython.org/FAQ/cdef_derive
- http://docs.cython.org/src/userguide/extension_types.html#external-
extension-types
- http://www.mail-archive.com/[email protected]/msg04857.html
I guess I was lucky too !
> "Easy" means that one can really just change def into cdef. And in
addition
> to that, I tried to call some frequently used routine directly, in order
to
> avoid a calling overhead, and also I cpdefined that routine.
No weird segfault and hardcore debugging. This is easy enough ! Cool !
> My preference is to do it on one ticket (the common topic being "cdefine
`ClasscallMetaclass`", which of course also involves cdefining
`NestedClassMetaclass`).
>
> Concerning clean review: I would provide a patch that is to be applied
before your patch (dealing with nested classes) and another one to be
applied after your patch (refactoring the bases of classcall metaclass).
>
> Hence, we can easily cross-review, which is considered to be "clean".
Excellent. I'm waiting for your input. I'll have time to review it at Sage
Days 38 if not before.
Florent
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12808#comment:39>
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.