#11342: Make getattr faster on parents and elements
---------------------------+------------------------------------------------
   Reporter:  SimonKing    |          Owner:  tbd                   
       Type:  enhancement  |         Status:  needs_review          
   Priority:  major        |      Milestone:  sage-4.7.1            
  Component:  performance  |       Keywords:  getattr parent element
Work_issues:               |       Upstream:  N/A                   
   Reviewer:               |         Author:  Simon King            
     Merged:               |   Dependencies:  #9944                 
---------------------------+------------------------------------------------

Comment(by SimonKing):

 I did the following test with lazy format strings:
 {{{
 sage: cython("""
 ....: from sage.misc.lazy_format import LazyFormat
 ....: def test(self,name,long m):
 ....:     s = LazyFormat("%s has no attribute %s")
 ....:     cdef long i
 ....:     for i from 0<=i<m:
 ....:         try:
 ....:             raise AttributeError, s%(self.__class__,name)
 ....:         except AttributeError:
 ....:             pass
 ....: """)
 }}}

 That string is a good approximation to what we really want, but the
 differences to the original error messages could only be resolved by a
 case distinction:
 {{{
 sage: s = LazyFormat("%s has no attribute %s")
 sage: raise AttributeError, s%(QQ.__class__,'bla')
 ---------------------------------------------------------------------------
 AttributeError                            Traceback (most recent call
 last)

 /home/king/<ipython console> in <module>()

 AttributeError: <class
 'sage.rings.rational_field.RationalField_with_category'> has no attribute
 bla
 sage: QQ.bla
 ...
 AttributeError: 'RationalField_with_category' object has no attribute
 'bla'
 }}}

 However, even if we do not insist on reproducing the exact same error
 message, lazy format strings are simply too slow.
 {{{
 sage: %time test(QQ,'bla',10^6)
 CPU times: user 16.12 s, sys: 0.01 s, total: 16.13 s
 Wall time: 16.12 s
 }}}

 So, it is nearly eight times slower than using `raise_attribute_error` in
 unpatched sage, and about fifty times slower than using
 `AttributeErrorMessage`, which was only 3 seconds for `10^7` (not `10^6`)
 iterations, and which ''does'' preserve the old error messages.

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