#12313: Fix yet another memory leak caused by caching of coercion data
--------------------------------------------------------+-------------------
       Reporter:  SimonKing                             |         Owner:        
                                               
           Type:  defect                                |        Status:  
needs_work                                           
       Priority:  major                                 |     Milestone:  
sage-5.7                                             
      Component:  memleak                               |    Resolution:        
                                               
       Keywords:  coercion weak dictionary              |   Work issues:        
                                               
Report Upstream:  N/A                                   |     Reviewers:  Simon 
King, Jean-Pierre Flori, John Perry, Nils Bruin
        Authors:  Simon King, Jean-Pierre Flori         |     Merged in:        
                                               
   Dependencies:  #715, #11521, #12215, #13746, #13378  |      Stopgaps:        
                                               
--------------------------------------------------------+-------------------

Comment (by SimonKing):

 Here is the outcome of
 {{{
 sage: from sage.combinat.sf.k_dual import DualkSchurFunctions
 sage: Sym = SymmetricFunctions(QQ['t'].fraction_field())
 sage: dks4 = DualkSchurFunctions(Sym.kBoundedQuotient(4))
 sage: %prun TestSuite(dks4).run()
 }}}

 First, sage-5.6.rc0 with #12215:
 {{{
      9365    7.254    0.001   11.881    0.001 {method 'subs' of
 'sage.structure.element.Element' objects}
     30786    2.596    0.000    3.067    0.000
 fraction_field.py:271(<lambda>)
   5358/84    1.781    0.000   26.087    0.311
 {sage.combinat.dict_addition.dict_linear_combination}
      1778    1.295    0.001   13.615    0.008 sfa.py:988(_from_cache)
     54541    1.061    0.000    2.015    0.000
 infinity.py:883(_element_constructor_)
    456782    1.051    0.000    1.051    0.000 {isinstance}
     27795    0.815    0.000    1.931    0.000
 partition.py:3510(Partitions)
    124520    0.754    0.000    0.754    0.000 fraction_field.py:430(ring)
      1715    0.518    0.000    2.106    0.001
 integer_list.py:192(rightmost_pivot)
      3951    0.433    0.000    0.547    0.000
 free_module.py:411(_coefficient_fast)
      4015    0.416    0.000    1.096    0.000
 polynomial_ring.py:290(_element_constructor_)
     54541    0.352    0.000    0.352    0.000 infinity.py:942(__init__)
      2236    0.348    0.000    0.448    0.000 free_module.py:562(support)
     80417    0.347    0.000    0.347    0.000 combinat.py:840(__hash__)
     37514    0.340    0.000    0.340    0.000 {method 'sub' of
 '_sre.SRE_Pattern' objects}
     37514    0.275    0.000    0.938    0.000 re.py:144(sub)
     51922    0.275    0.000    0.275    0.000 partition.py:4003(__repr__)
     19970    0.262    0.000    2.203    0.000 partition.py:2716(parent)
     16195    0.259    0.000    0.515    0.000
 free_module.py:2142(_from_dict)
     37514    0.244    0.000    0.322    0.000 re.py:226(_compile)
      4015    0.238    0.000    1.933    0.000
 fraction_field.py:456(_element_constructor_)
     39940    0.232    0.000    0.580    0.000 {repr}
      9365    0.230    0.000    0.292    0.000 fraction_field.py:532(gen)
     35636    0.186    0.000    0.305    0.000 infinity.py:285(__cmp__)
      1715    0.186    0.000    0.634    0.000 integer_list.py:38(first)
 }}}

 Second, adding #13378
 {{{
      9365    7.525    0.001   12.378    0.001 {method 'subs' of
 'sage.structure.element.Element' objects}
     30786    2.666    0.000    3.166    0.000
 fraction_field.py:271(<lambda>)
   5363/85    1.908    0.000   29.846    0.351
 {sage.combinat.dict_addition.dict_linear_combination}
      1778    1.340    0.001   15.319    0.009 sfa.py:988(_from_cache)
    494409    1.269    0.000    1.269    0.000 {isinstance}
     55877    1.196    0.000    2.254    0.000
 infinity.py:883(_element_constructor_)
     27906    0.876    0.000    2.117    0.000
 partition.py:3510(Partitions)
    127929    0.809    0.000    0.809    0.000 fraction_field.py:430(ring)
      1855    0.561    0.000    2.359    0.001
 integer_list.py:192(rightmost_pivot)
 4248/4191    0.493    0.000    1.256    0.000
 polynomial_ring.py:290(_element_constructor_)
      4070    0.461    0.000    0.591    0.000
 free_module.py:411(_coefficient_fast)
     82386    0.397    0.000    0.397    0.000 combinat.py:840(__hash__)
      2236    0.374    0.000    0.498    0.000 free_module.py:562(support)
     55877    0.372    0.000    0.372    0.000 infinity.py:942(__init__)
     37516    0.367    0.000    0.369    0.000 {method 'sub' of
 '_sre.SRE_Pattern' objects}
     46893    0.326    0.000    0.764    0.000 {repr}
     56811    0.318    0.000    0.318    0.000 partition.py:4003(__repr__)
     37514    0.304    0.000    1.020    0.000 re.py:144(sub)
     16322    0.301    0.000    0.601    0.000
 free_module.py:2142(_from_dict)
     19970    0.290    0.000    2.418    0.000 partition.py:2716(parent)
     37517    0.265    0.000    0.362    0.000 re.py:226(_compile)
      4015    0.261    0.000    2.149    0.001
 fraction_field.py:456(_element_constructor_)
      9426    0.239    0.000    0.312    0.000 fraction_field.py:532(gen)
     17385    0.223    0.000    0.365    0.000 combinat.py:667(__init__)
     36359    0.216    0.000    0.349    0.000 infinity.py:285(__cmp__)
 }}}

 And finally adding #12313:
 {{{
 952735/392465   59.690    0.000  204.150    0.001 {method
 'has_coerce_map_from' of 'sage.structure.parent.Parent' objects}
   3818389   44.077    0.000   91.652    0.000 {repr}
      1626   27.430    0.017  243.763    0.150 k_dual.py:1277(<genexpr>)
    475630   24.414    0.000   71.594    0.000 {method 'coerce_map_from' of
 'sage.structure.parent.Parent' objects}
    471632   23.574    0.000  204.044    0.000
 fraction_field.py:194(_coerce_map_from_)
   1909173   15.683    0.000  111.239    0.000 combinat.py:1051(__cmp__)
   1425904   15.023    0.000   23.084    0.000
 polynomial_ring.py:1369(_repr_)
 475629/475628   13.746    0.000   90.469    0.000
 polynomial_ring.py:468(_coerce_map_from_)
   3286022   12.918    0.000   17.094    0.000
 unique_representation.py:531(__hash__)
       558   11.842    0.021   73.743    0.132 k_dual.py:1234(<genexpr>)
    475332   11.785    0.000   19.538    0.000
 fraction_field.py:380(_repr_)
   1925108   11.632    0.000   11.632    0.000 partition.py:4003(__repr__)
   1439041    8.110    0.000    8.110    0.000
 polynomial_ring.py:716(__hash__)
   1425904    8.061    0.000    8.061    0.000
 polynomial_ring.py:725(_repr_)
      9365    7.681    0.001   12.918    0.001 {method 'subs' of
 'sage.structure.element.Element' objects}
     16080    7.001    0.000    9.528    0.001 homset.py:353(__init__)
   1934768    5.774    0.000    5.774    0.000 {isinstance}
       564    5.764    0.010   33.683    0.060 k_dual.py:1110(<genexpr>)
   3334205    4.241    0.000    4.241    0.000 {id}
   1927477    3.937    0.000    3.937    0.000 {cmp}
   1450944    3.416    0.000    3.416    0.000
 rational_field.py:217(__hash__)
    479620    3.123    0.000   24.605    0.000
 rational_field.py:261(_coerce_map_from_)
     30786    3.106    0.000    3.593    0.000
 fraction_field.py:271(<lambda>)
     16060    2.354    0.000   13.278    0.001 homset.py:80(Hom)
       315    2.335    0.007   50.641    0.161 k_dual.py:1076(retract)
 }}}

 I'm afraid I have to leave now. But the fact that repr is called so often
 makes me guess that there is indeed caching involved - namely with a hash
 function that relies on the string representation. But if that was
 correct, neither `MonoDict` nor `TripleDict` are to blame: They compare by
 identity and thus don't rely on the hash of the keys.

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