Hi!

The background of my question is trac ticket #11115. It provides a
Cython version of @cached_method, and it is really fast now.

Apart from the speed up, another problem is addressed: If an element
or parent structure is an extension class that does not allow
attribute assignment then it can still inherit cached methods from the
category framework -- but currently, the cache would break without
attribute assignment. Moreover, calling a cached method has a huge
overhead if attributes can't be assigned.

I suggest to introduce a new "cdef public dict" attribute
__cached_methods for both sage.structure.parent.Parent and
sage.structure.element.Element. If the cached method finds that
attribute assignment does not work then it will use __cached_methods
to store stuff. Then, the cache works, and the overhead is reduced
(although it is still faster with proper attribute assignment).

It works fine and doctests pass. However, Nicolas suggested that we
should discuss on sage-devel whether it is ok to introduce a new
attribute to any element (he said that it should be fine for parents,
as there are far less parents than elements).

My opinion:

If you consider an Element x that allows attribute assignment then the
only change with my patch is that x has an additional uninitialised
(i.e., None) attribute. If x does not allow attribute assignment and
x.parent().category().element_class provides a cached method (I don't
know if that exists, yet) then stuff would be stored in
x.__cached_methods that would otherwise be stored in, say, x.__dict__,
if it *would* allow attribute assignment.

So, I believe that the additional attribute can be afforded.

What do you think?

Best regards,
Simon

-- 
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to