# Should Julia be able to optimize away small temporary arrays?

**URL:** <https://discourse.julialang.org/t/should-julia-be-able-to-optimize-away-small-temporary-arrays/84648>\
**Category:** New to Julia\
**Tags:** question, performance, array, tuple\
**Created:** [July 22, 2022, 6:23pm UTC](https://discourse.julialang.org/t/should-julia-be-able-to-optimize-away-small-temporary-arrays/84648 "2022-07-22T18:23:43Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [July 23, 2022, 6:23am UTC](https://discourse.julialang.org/t/should-julia-be-able-to-optimize-away-small-temporary-arrays/84648/10 "2022-07-23T06:23:19Z")

</div>

> [@stillyslalom](#):
>
> an array literal filled with numeric literals which clearly doesn’t change size

Is this actually feasible to detect for vectors? I can easily imagine heap-to-stack optimizations for mutable structs because the size is fixed, and while I’m not as certain, I think \>=2-dimensional arrays also can’t change their size. But vectors definitely have dynamic sizes, and while it’s simple enough to check for `push!`, `popat!`, etc. in the method, these calls could also happen in very nested method calls. Is the compiler capable of ruling out resizing in all nested non-inlined calls, or would it just give up even when the programmer knows none of those methods resize the array?

That said, mutable `StaticArray`s could end up on the stack more readily than [they already do](https://discourse.julialang.org/t/can-julia-optimize-mutable-static-arrays-to-be-allocated-on-the-stack/66360/2).

---

_[View the full topic](https://discourse.julialang.org/t/should-julia-be-able-to-optimize-away-small-temporary-arrays/84648)._
