# Speed up solution system of ODEs

**URL:** <https://discourse.julialang.org/t/speed-up-solution-system-of-odes/24620>\
**Category:** New to Julia\
**Tags:** diffeq\
**Created:** [May 26, 2019, 2:22pm UTC](https://discourse.julialang.org/t/speed-up-solution-system-of-odes/24620 "2019-05-26T14:22:00Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![dawbarton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dawbarton/32/215461_2.png) [@dawbarton](https://discourse.julialang.org/u/dawbarton)\
**Post date:** [June 2, 2019, 3:38pm UTC](https://discourse.julialang.org/t/speed-up-solution-system-of-odes/24620/21 "2019-06-02T15:38:11Z")

</div>

I think that’s a useful summary. I’d emphasise that, other than avoiding global variables, I’d just write the code in the most straightforward way I can think of and then **only** start optimising if the performance really isn’t good enough. The garbage collector is reasonably good and so I often don’t worry about the allocations that much unless the code is going to be run a lot.

> [@BLI](#):
>
> If I introduce a single temporary assignment, say, `a = 10` , or ten thousand assignments `a = 10; b = 5; ...` inside a function call — will that cause the allocation of memory for a single variable or ten thousand variables _every time I call the function_ ?

One small point of clarification; it’s not assignments (`a = ...`) that cause allocations, it’s the operation on the right-hand side, e.g., `a = b + c` where `b` and `c` are vectors. In this case the result of `b + c` is allocated and it’s immaterial whether this is assigned to a variable or used within a larger calculation. As such, don’t be worried about assignments. (Note that in this case, this is where the broadcasting facilities of Julia come in to help reduce allocations - see [this nice blog post](https://julialang.org/blog/2017/01/moredots) for more information, particularly the section on “Why vectorised code is not as fast as it could be”.)

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [June 2, 2019, 4:40pm UTC](https://discourse.julialang.org/t/speed-up-solution-system-of-odes/24620/22 "2019-06-02T16:40:11Z")

</div>

Thanks. Btw… if I have made a global variable `const` — is there a way to “clear” it or release the constancy, or is this only possible if I close down that current Julia session?

---

<div class="post-metadata">

**Author:** ![dawbarton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dawbarton/32/215461_2.png) [@dawbarton](https://discourse.julialang.org/u/dawbarton)\
**Post date:** [June 2, 2019, 4:46pm UTC](https://discourse.julialang.org/t/speed-up-solution-system-of-odes/24620/23 "2019-06-02T16:46:46Z")

</div>

I think restarting Julia is the only way but I could easily be wrong.

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [June 2, 2019, 6:56pm UTC](https://discourse.julialang.org/t/speed-up-solution-system-of-odes/24620/24 "2019-06-02T18:56:14Z")

</div>

> [@BLI](#):
>
> But strings are immutable – so why are they allocated on the heap?

In general you can’t know how big a string is at compile time (Like for example if you are reading it in from a file), and strings can be big… like the entire contents of Moby Dick or the 4th mouse chromosome, or whatever, you wouldn’t allocate that on a stack.

[Previous page](https://discourse.julialang.org/t/speed-up-solution-system-of-odes/24620.md?page=1)
