#14058: Weakly reference binary operation codomains
-----------------------------------+----------------------------------------
       Reporter:  robertwb         |         Owner:  rlm         
           Type:  enhancement      |        Status:  needs_review
       Priority:  major            |     Milestone:  sage-5.7    
      Component:  memleak          |    Resolution:              
       Keywords:                   |   Work issues:              
Report Upstream:  N/A              |     Reviewers:              
        Authors:  Robert Bradshaw  |     Merged in:              
   Dependencies:  #12313           |      Stopgaps:              
-----------------------------------+----------------------------------------

Comment (by nbruin):

 > I doubt that we want that. It is not desirable that, when adding
 elements of `ZZ['x']` and QQ, the ring `QQ['x']` is created repeatedly
 (OK, polynomial rings have a strong cache anyway. But you see what I
 mean).

 In my opinion, that is exactly what we want, or at least what we have to
 settle for. If a person wants to work efficiently with `QQ['x']` he should
 ensure his elements already live there. Adding elements with the same
 parents is orders of magnitude faster than relying on coercion. A step
 closer is ensure that your parent remains in memory. I suspect that
 usually that will be the case, because if a user creates elements
 somewhere regularly he probably

 In this scenario:
 {{{
 P=[ZZ['x%d'%i] for i in [1..1000]]
 F=[GF(p) for p in prime_range(1000)]
 for Zxi in P:
     for k in F:
         a=P.0
         b=F(1)
         c=a+b
 }}}
 If we keep the `GF(p)[xi]` alive because at some point we constructed an
 element in it from parents that are still around, we've just created
 quadratic memory requirements where linear should be enough.

 I don't think that we can afford to assume that just because a user has
 combined two parents he/she will do so again in the future. We may be able
 to afford doing so if it happened ''recently'', but that really is an
 optimisation, and currently I don't see a hook where we can do this
 efficiently.

 A limited length buffer that gets updated whenever a certain component
 sees a parent go by might work. In Coercion ''discovery'' perhaps? That's
 already slow and it would exactly protect these automatically generated
 parents. Logically it's hard to defend but it may be OK in practice.

 Another possibility is just `UniqueRepresentation_c.__cinit__`. Only when
 we're making a lot of parents do we care about losing them again ...

 The problem with artificially keeping transient elements alive for longer
 is that you'll defeat the heuristics for generational garbage collection
 (which Python does), and we depend rather heavily on that to get rid of
 cyclic garbage. Testing would be required to see if this is indeed a
 problem, and it will be very application-dependent.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14058#comment:14>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to