#11900: Serious regression caused by #9138
---------------------------+------------------------------------------------
   Reporter:  SimonKing    |          Owner:  tbd                  
       Type:  defect       |         Status:  needs_review         
   Priority:  major        |      Milestone:  sage-4.7.3           
  Component:  performance  |       Keywords:  categories regression
Work_issues:               |       Upstream:  N/A                  
   Reviewer:               |         Author:  Simon King           
     Merged:               |   Dependencies:  #9138 #11911         
---------------------------+------------------------------------------------

Comment(by SimonKing):

 Here is `%prun test(L)` for the following test of univariate polynomial
 ring creation:
 {{{
 sage: L = [GF(p) for p in prime_range(10000)]
 sage: def test(L):
 ....:     for K in L:
 ....:         P = K['x']
 ....:
 }}}

 (1)
 {{{
    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      3686    0.215    0.000    0.412    0.000 homset.py:248(__init__)
      1229    0.193    0.000    1.047    0.001
 polynomial_ring.py:235(__init__)
 7372/3686    0.094    0.000    0.126    0.000
 lazy_attribute.py:493(__get__)
      3686    0.070    0.000    0.629    0.000 homset.py:40(Hom)
      1229    0.054    0.000    0.054    0.000 {method
 '_unset_coercions_used' of 'sage.structure.parent.Parent' objects}
     25803    0.040    0.000    0.113    0.000 {hasattr}
     23346    0.039    0.000    0.039    0.000 {method 'fix_to_pos' of
 'sage.misc.function_mangling.ArgumentFixer' objects}
      1229    0.039    0.000    0.226    0.000 {method
 '_populate_coercion_lists_' of 'sage.structure.parent.Parent' objects}
     14745    0.036    0.000    0.098    0.000
 classcall_metaclass.py:131(__call__)
      1228    0.035    0.000    0.314    0.000
 finite_field_prime_modn.py:128(_coerce_map_from_)
     17203    0.032    0.000    0.064    0.000 cachefunc.py:147(__call__)
      1229    0.031    0.000    1.103    0.001
 polynomial_ring.py:1954(__init__)
      3687    0.025    0.000    0.030    0.000
 polynomial_ring.py:673(__hash__)
     17200    0.023    0.000    0.023    0.000
 finite_field_prime_modn.py:223(order)
      1229    0.020    0.000    1.169    0.001
 polynomial_ring_constructor.py:443(_single_variate)
 6144/6143    0.018    0.000    0.038    0.000 cachefunc.py:505(__call__)
      1229    0.014    0.000    0.016    0.000 {method 'is_prime' of
 'sage.rings.integer.Integer' objects}
      1229    0.013    0.000    1.065    0.001
 polynomial_ring.py:1874(__init__)
         1    0.013    0.013    1.201    1.201 <ipython console>:1(test)
      6143    0.011    0.000    0.067    0.000
 category.py:974(hom_category)
      1229    0.011    0.000    0.153    0.000 {method '_Hom_' of
 'sage.rings.finite_rings.finite_field_base.FiniteField' objects}
      1229    0.011    0.000    1.189    0.001
 polynomial_ring_constructor.py:48(PolynomialRing)
      3688    0.010    0.000    0.041    0.000 {method 'has_key' of 'dict'
 objects}
     14748    0.009    0.000    0.009    0.000 {isinstance}
      1229    0.008    0.000    0.142    0.000 homset.py:29(__init__)
      1229    0.007    0.000    0.009    0.000
 polynomial_ring_constructor.py:427(_get_from_cache)
      1229    0.007    0.000    0.009    0.000
 {sage.structure.parent_gens.normalize_names}
     14744    0.007    0.000    0.010    0.000
 unique_representation.py:514(__hash__)
      7372    0.007    0.000    0.007    0.000 {getattr}
      1228    0.007    0.000    0.007    0.000
 {sage.rings.finite_rings.integer_mod.IntegerMod}
      2458    0.006    0.000    0.014    0.000
 dynamic_class.py:122(dynamic_class)
 }}}

 (2) As you can see, an awful lot of the time is spent for creation of the
 parent classes and for is_subcategory() tests:
 {{{
    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     11055    0.877    0.000    0.879    0.000
 dynamic_class.py:258(dynamic_class_internal)
 320769/3687    0.510    0.000    1.812    0.000
 category.py:588(add_successors)
 9826/1229    0.421    0.000    1.457    0.001
 category.py:628(parent_class)
 374826/34402    0.398    0.000    2.701    0.000
 cachefunc.py:505(__call__)
 72485/61432    0.381    0.000    2.185    0.000 cachefunc.py:147(__call__)
      9826    0.269    0.000    0.765    0.000
 unique_representation.py:435(__classcall__)
      3687    0.232    0.000    2.245    0.001
 category.py:554(all_super_categories)
    121627    0.219    0.000    0.219    0.000 {method 'fix_to_pos' of
 'sage.misc.function_mangling.ArgumentFixer' objects}00    6.292    0.005
 polynomial_ring.py:237(__init__)
      6144    0.217    0.000    0.555    0.000 homset.py:287(__init__)
 22114/7373    0.179    0.000    1.670    0.000
 lazy_attribute.py:493(__get__)
 58971/45462    0.164    0.000    1.228    0.000
 classcall_metaclass.py:131(__call__)
      9826    0.157    0.000    0.211    0.000 category.py:323(__init__)
    486657    0.145    0.000    0.189    0.000
 unique_representation.py:514(__hash__)
      9832    0.114    0.000    2.485    0.000
 category.py:679(is_subcategory)
 4916/2458    0.104    0.000    0.613    0.000 {method 'coerce_map_from' of
 'sage.structure.parent.Parent' objects}7    0.000    0.208    0.000
 {hasattr}
     56514    0.081    0.000    0.081    0.000
 finite_field_prime_modn.py:224(order)
      6144    0.078    0.000    1.513    0.000 homset.py:39(Hom)
      3687    0.068    0.000    2.231    0.001 category.py:868(join)
      7369    0.060    0.000    0.350    0.000
 category_types.py:262(__init__)
      1229    0.058    0.000    0.058    0.000 {method
 '_unset_coercions_used' of 'sage.structure.parent.Parent' objects}.000
 0.170    0.000 cachefunc.py:804(__get__)
     79885    0.051    0.000    0.079    0.000 {method 'add' of 'set'
 objects}
    396967    0.050    0.000    0.050    0.000 {method 'append' of 'list'
 objects}
 2458/1229    0.047    0.000    0.628    0.001
 polynomial_ring.py:470(_coerce_map_from_)
     14742    0.046    0.000    1.190    0.000
 dynamic_class.py:122(dynamic_class)
 }}}

 (3) To my surprise, with my patches, the picture remains the same. I'll
 try to fix it.
 {{{
    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     11061    1.211    0.000    1.213    0.000
 dynamic_class.py:258(dynamic_class_internal)
 67595/6145    0.660    0.000    2.958    0.000
 category.py:702(is_subcategory)
 191717/34406    0.636    0.000    3.132    0.000
 cachefunc.py:505(__call__)
    172054    0.501    0.000    0.501    0.000 {method 'fix_to_pos' of
 'sage.misc.function_mangling.ArgumentFixer' objects}/22121    0.251
 0.000    4.792    0.000 cachefunc.py:147(__call__)
      1229    0.233    0.000    5.394    0.004
 polynomial_ring.py:246(__init__)
 146251/14748    0.163    0.000    2.788    0.000
 category.py:757(<genexpr>)
      9831    0.159    0.000    0.213    0.000 category.py:350(__init__)
 77426/7373    0.098    0.000    2.973    0.000
 cachefunc.py:733(_instance_call)
    130272    0.097    0.000    0.097    0.000 {getattr}
    121667    0.096    0.000    0.514    0.000 cachefunc.py:559(get_key)
 36868/23350    0.095    0.000    0.810    0.000
 classcall_metaclass.py:131(__call__)
    167141    0.087    0.000    0.087    0.000 {isinstance}
    226131    0.086    0.000    0.112    0.000
 unique_representation.py:514(__hash__)
 9832/1229    0.069    0.000    1.315    0.001
 category.py:651(parent_class)
      3687    0.065    0.000    3.283    0.001 category.py:62(_join)
      7373    0.059    0.000    0.332    0.000
 category_types.py:262(__init__)
 76198/13519    0.055    0.000    2.885    0.000 {any}
     18434    0.055    0.000    0.175    0.000 cachefunc.py:804(__get__)
     35633    0.054    0.000    0.054    0.000
 finite_field_prime_modn.py:224(order)
 12288/2457    0.051    0.000    1.361    0.001
 lazy_attribute.py:493(__get__)
      9831    0.046    0.000    0.509    0.000
 unique_representation.py:435(__classcall__)
     18434    0.038    0.000    0.080    0.000 cachefunc.py:457(__init__)
      1228    0.037    0.000    0.202    0.000
 finite_field_prime_modn.py:129(_coerce_map_from_)
      1228    0.036    0.000    0.088    0.000 homset.py:287(__init__)
     11061    0.036    0.000    1.384    0.000
 dynamic_class.py:122(dynamic_class)
 }}}

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