#11115: Rewrite cached_method in Cython
---------------------------+------------------------------------------------
   Reporter:  SimonKing    |          Owner:  jason                
       Type:  enhancement  |         Status:  needs_review         
   Priority:  major        |      Milestone:  sage-4.7             
  Component:  misc         |       Keywords:  category cython cache
Work_issues:               |       Upstream:  N/A                  
   Reviewer:               |         Author:  Simon King           
     Merged:               |   Dependencies:                       
---------------------------+------------------------------------------------

Comment(by SimonKing):

 Hi Andrey,

 Replying to [comment:28 novoselt]:
 > And as I understand, things don't break if you forget to do it, they
 just work slower than they should.

 What scenario does your statement refer to? (1) The status quo, (2) the
 patch as it is, or (3) the patch without
 `sage.structure.element.Element.__cached_methods`?

 Here is my view on these three:

 (1) Cached methods have been improved in #8611, but they are still not
 fast enough, for my taste. Time and memory is wasted by assigning a
 `__doc__` string to each instance of a cached method (that is noticeable
 in the startup time). It can only be used in Python code. If a parent or
 an element does not accept attribute assignment then it can inherit a
 cached_method from the category -- but the cache breaks ''and'' there is a
 huge overhead. cached_in_parent_method can not be inherited from the
 category at all.

 (2) cached_method can compete with a hand-written cache in Python, speed-
 wise, provided that attribute assignment is possible. `__doc__` is now
 replaced by `_sage_doc_`, which is used by sage's introspection anyway and
 computes the docstring only when requested. It can, to some extent, be
 used in Cython code. If a parent or an element does not accept attribute
 assignment then it can inherit a cached_method from the category: The
 return values ''are'' cached ("things don't break), but there is an
 overhead (though much less than in (1)). The price to pay is 0.24% more
 memory consumption at startup. cached_in_parent_method can be inherited
 from the category.

 (3) (Hypothetical) Cached methods are supported for elements only if
 either the element allows attribute assignment, or the user did not forget
 to provide it with a public attribute `__cached_methods`. If neither of
 these conditions hold then things behave as in (1), for elements. In
 particular, for an element that does not satisfy the conditions, the cache
 of cached_method will break and will have a huge overhead. However,
 cached_in_parent_method is fully supported (that is since the cache is in
 the parent, and parents ''have'' `__cached_methods` in scenario (3)).

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11115#comment:29>
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.

Reply via email to