# Compiler optimizations with broadcast or map

**URL:** https://discourse.julialang.org/t/compiler-optimizations-with-broadcast-or-map/42119
**Category:** Performance
**Tags:** compilation
**Created:** [June 26, 2020, 6:09pm UTC](https://discourse.julialang.org/t/compiler-optimizations-with-broadcast-or-map/42119 "2020-06-26T18:09:41Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [June 27, 2020, 12:28pm UTC](https://discourse.julialang.org/t/compiler-optimizations-with-broadcast-or-map/42119/4 "2020-06-27T12:28:22Z")

</div>

> [@kschurter](#):
>
> assuming we have told the compiler everything it needs to know that `length(data)` is the same each time it is allocated in these blocks

I am not sure how you plan to do that. Also, I don’ t understand why you think that `length(data)` is “allocated”, there shouldn’t be any allocation.

Generally, the compiler will elide repeated evaluations of functions it considers “pure” (see eg [this discussion](https://discourse.julialang.org/t/pure-macro/3871)). You can provide hint for this using `Base.@pure`, but that is not recommended unless you really know what you are doing. Given that your code has mistakes that would prevent it from working correctly as is (eg `data - x` instead of `data .- x`), I am not sure I would suggest pursuing that.

In your example, I don’t think that that repeated calls to `length` are elided. But `length` of a vector is a very, very cheap operation, I would not worry about this.

---

_[View the full topic](https://discourse.julialang.org/t/compiler-optimizations-with-broadcast-or-map/42119)._
