Hi Gabriel,
On 2014-05-25, Gabriel Furstenheim Milerud <
furst...@gmail.com> wrote:
> There is a memory leak in the evaluation of multivariable polynomials:
>
> -C.<x,y,z>=GF(2)[]
> -f=x^4+x*y^3+z^6
>
> -get_memory_usage()
> .....1014.47265625
> - for i in xrange(1000000):
> a=f(1,0,0)
> -get_memory_usage()
> .....1052.47265625
Note that you first request the memory usage before assigning
"a=f(1,0,0)". But to some extend, I can confirm an increase of memory
usage (with Sage 6.2):
sage: C.<x,y,z> = GF(2)[]
sage: f = x^4+x*y^3+z^6
sage: a = f(1,0,0)
sage: get_memory_usage()
176.08984375
sage: for i in xrange(1000000):
....: a = f(1,0,0)
....:
sage: get_memory_usage()
198.08984375
sage: for i in xrange(1000000):
....: a = f(1,0,0)
....:
sage: get_memory_usage()
222.08984375
We have an increase of 22-24 megabytes in 10^6 rounds, thus 23-25 byte per round.
Actually I wonder how such a tiny leak is even possible! In any case, it
should be fixed.
> try:
> K = x[0].parent()
> except AttributeError:
> K = self.parent().base_ring()
> y = K(0)
> for (m,c) in self.element().dict().iteritems():
> y += c*misc.mul([ x[i]**m[i] for i in range(n) if m[i] != 0])
> return y
>
> So in every loop a new ring K is created and saved
No, K is already there, it is either x[0].parent() or self.parent().base_ring().
Actually it is K=GF(2), if I am not mistaken. Moreover, I don't think this branch
of code is evaluated in your example.
Anyway, thank you for the example!
Best regards,
Simon