# Structs and parametric constructors

**URL:** https://discourse.julialang.org/t/structs-and-parametric-constructors/18684
**Category:** New to Julia
**Created:** [December 15, 2018, 11:48am UTC](https://discourse.julialang.org/t/structs-and-parametric-constructors/18684 "2018-12-15T11:48:07Z")
**Posts on this page:** 1
**Showing post:** 14

<div class="post-metadata">

### Author: ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)
#### Post date: [December 15, 2018, 4:40pm UTC](https://discourse.julialang.org/t/structs-and-parametric-constructors/18684/14 "2018-12-15T16:40:36Z")

</div>

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

> [@ckoe-bccms](#):
>
> This includes an additional `if` , as you probably know the Newton fractal can also be defined for e.g. `sin()` which has a single real root and I should simplify that, I know.

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

---

_[View the full topic](https://discourse.julialang.org/t/structs-and-parametric-constructors/18684)._
