Parsing Julia code with a large array is very slow or results in `StackOverflowError`

You might not need the polynominals as code in the array. You’re generating a lot of code. It might be faster to only have an array of polynominal coefficients, and run evalpoly function (horner-rule) on them at runtime.

I suppose you do not have a constant polynominal, but then this is much faster…

function badcode(N::Int)
         io = IOBuffer()
         println(io, "x = 2; f(x) = x^7+x^6+x^5+x^4+x+1")
         println(io, "ll = [")
         for i in 1:N
           println(io, "[$i, f(x)],")
         end
         println(io, "]")
         return String(take!(io))
       end
1 Like