#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 SimonKing):

 Replying to [comment:14 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.

 Granted. But it is a very typical usage to ''not'' explicitly convert
 everything into a common parent, but let the coercion model do the work.
 That is what the coercion model is for!

 >  I suspect that usually that will be the case, because if a user creates
 elements somewhere regularly he probably

 However, in the example that I posted above, note that multiplying
 `OA(1)*OB(1)` repeatedly will also create `C()` ''repeatedly'', even
 though it is a `UniqueRepresentation` and hence (weakly, nowadays) cached!

 I think it is not acceptable that a multiple creation is triggered.

 >
 > 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.

 In your example, `GF(p)[xi]` is created exactly once, for each value of p
 and i. Clearly, in this situation it would not make sense to keep it
 alive, because it is never reused. However, I doubt that this is a typical
 use case.

 > 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 ...

 OK, but not all unique parent structures rely on it.

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