Structs and parametric constructors

Well, I am a german speaker also, but probably not everyone on this website is.

What you could do is write a single while loop, which has the if statement inside the condition, as I have done in my code shown above.

Amazingly, with this improvement the difference is enormous for larger n, with old definition

julia> newton(:(z^3-1);n=1500)|>fatou;
 19.215167 seconds (65.07 M allocations: 1.817 GiB, 7.66% gc time)

However, with new definition

julia> newton(:(z^3-1);n=1500)|>fatou;
  0.175065 seconds (541 allocations: 36.706 KiB)

julia> newton(:(z^3-1);n=2500)|>fatou;
  0.490495 seconds (542 allocations: 36.784 KiB)

julia> newton(:(z^3-1);n=3500)|>fatou;
  1.004239 seconds (541 allocations: 36.706 KiB)

Clearly, the memory consumption and allocations are greatly reduced. I believe this is because in my original version, the @threads parallel processing had to assign the memory for Fatou.Define object every time to determine the Bool parameters for Mandelbrot and Newton mode. Having these Bool and Function available in the type parameter for Fatou.Define enables the compiler to leave out the full reference to the original Fatou.Define object, I suspect, and is probably inlining everything now.

So if you include enough type parameters to make the original struct obsolete, I think that’s the trick, so that the bigger object does not need to be re-assigned for parallel computations.

1 Like