# Intermediate results (dereferencing, CSE, ..) - when to avoid?

**URL:** <https://discourse.julialang.org/t/intermediate-results-dereferencing-cse-when-to-avoid/66024>\
**Category:** Performance\
**Created:** [August 8, 2021, 3:48pm UTC](https://discourse.julialang.org/t/intermediate-results-dereferencing-cse-when-to-avoid/66024 "2021-08-08T15:48:44Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [August 8, 2021, 4:52pm UTC](https://discourse.julialang.org/t/intermediate-results-dereferencing-cse-when-to-avoid/66024/3 "2021-08-08T16:52:54Z")

</div>

> [@Bardo](#):
>
> seems to suggest avoiding intermediate variables…

I think there’s some misconception here. The intermediate is still allocated, even if you don’t assign a name to it. The object

```julia
fieldnames(typeof(first(v)))

```

is created and allocated, not naming it doesn’t help, it will just be assigned some internal label instead.

In cases where the intermediate is just some value, that does not need to be heap allocated, the allocations don’t matter either way, and you can create temporary variables to your heart’s content. But if the intermediate is an array, for example, then you get a real, and possibly expensive allocation over and over.

So in your case it’s not a trade-off, it’s just worse in every way to not assign the intermediate.

---

_[View the full topic](https://discourse.julialang.org/t/intermediate-results-dereferencing-cse-when-to-avoid/66024)._
