#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, Simon King | Merged in:
Dependencies: | Stopgaps:
--------------------------------------------------+-------------------------
Comment (by SimonKing):
Dear Florent,
Replying to [comment:42 hivert]:
> I fully agree that it is clearer. There may be however some speed
penalty with
> getting rid of {{{ClasscallType}}} if we need at some point to construct
a lot
> of classes which need the classcall trick but without nested classes.
Well, the problem is as I have explained in the sage-combinat-devel
thread. Some classes would actually not use more than the `__call__`
method (so, morally, `ClasscallMetaclass` should only do this one thing),
while some would only need nesting or another `__init__` (so,
`NestedClassMetaclass` should only do this one thing), and others only
need a custom `__reduce__` method (so, `DynamicMetaclass` should only to
this one thing).
However, in typical applications, we want to construct a class that
simultaneously derives from classes with different metaclasses. That is
only possible if we have metaclasses that combine different features.
Hence, `ClasscallMetaclass` inherits from `NestedClassMetaclass` (although
it often does not need nesting), and there is an additional
`DynamicClasscallMetaclass`, just to cope with dynamic classes that have a
classcall.
I'd really like to have these combined metaclasses created automatically,
hence, using a meta-metaclass.
Concerning time penalty: As I have demonstrated above, there is no time
penalty for special methods of a class C that are inherited from different
Cython classes - even if the inheritance is indirect. A speed penalty only
seems to occur, if one has an ''indirect'' inheritance of ''non-magical''
methods.
Hence, if C is actually used as a metaclass, I would expect that both
approaches (defining the fast magical methods in `ClasscallType` and other
auxiliar types or directly in `ClasscallMetaclass` and other metaclasses)
are equal, speed-wise.
> I don't
> know if this usecase is realistic at all.
See above: There ''is'' need for combined metaclasses, even though in some
applications a pure one-trick metaclass would be enough.
> Anyway,
> there won't be any overhead from the point of view of the instances
creation
> and, manipulation but there may be when creating the '''classes'''
> themselves.
Well, the timings that I presented were for a class C, and I measured some
methods (e.g. `__call__`) of its instances. However, I think the same
observations will hold if C actually is a ''meta''class, and we would
measure `__call__` etc. of its instances (which are classes).
But of course the time for creating (not just for calling) the instances
matters as well.
Cheers,
Simon
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12808#comment:43>
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.