# .== performance regression

**URL:** <https://discourse.julialang.org/t/performance-regression/5709>\
**Category:** New to Julia\
**Created:** [September 4, 2017, 1:45am UTC](https://discourse.julialang.org/t/performance-regression/5709 "2017-09-04T01:45:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![augustinyiptong](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/augustinyiptong/32/1785_2.png) [@augustinyiptong](https://discourse.julialang.org/u/augustinyiptong)\
**Post date:** [September 4, 2017, 1:45am UTC](https://discourse.julialang.org/t/performance-regression/5709/1 "2017-09-04T01:45:44Z")

</div>

Apologies if this has already been addressed:

In 0.5.2  
`@time [1,2,3] .== 2`  
`0.000013 seconds (9 allocations: 4.594 KB)`

In 0.6.0  
`0.028732 seconds (6.24 k allocations: 344.770 KiB)`

I know 0.6.0 changed the way the ‘dot’ works, but this performance regression is big. Am I missing something obvious?

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [September 4, 2017, 1:57am UTC](https://discourse.julialang.org/t/performance-regression/5709/2 "2017-09-04T01:57:44Z")

</div>

```julia
julia> using BenchmarkTools

julia> @btime $[1,2,3] .== 2
  810.962 ns (4 allocations: 4.33 KiB)

```

but in 0.5:

```julia
julia> @btime $[1,2,3] .== 2
  2.091 μs (4 allocations: 4.33 KiB)

```

When working at the REPL, you have to be careful with what you’re profiling. Your `@time` is probably measuring mostly just the dispatch time, and the time to create the vector. `@btime` is generally much more accurate. The dollar sign tells it to evaluate `[1,2,3]` before starting to measure the time.

---

<div class="post-metadata">

**Author:** ![augustinyiptong](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/augustinyiptong/32/1785_2.png) [@augustinyiptong](https://discourse.julialang.org/u/augustinyiptong)\
**Post date:** [September 4, 2017, 2:08am UTC](https://discourse.julialang.org/t/performance-regression/5709/3 "2017-09-04T02:08:27Z")

</div>

rookie mistake, thanks!

---

<div class="post-metadata">

**Author:** ![Chong\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chong_wang/32/20307_2.png) [@Chong\_Wang](https://discourse.julialang.org/u/Chong_Wang)\
**Post date:** [September 4, 2017, 4:13pm UTC](https://discourse.julialang.org/t/performance-regression/5709/4 "2017-09-04T16:13:08Z")

</div>

> [@augustinyiptong](#):
>
> @time [1,2,3] .== 2

It is still weird `@time [1,2,3] .== 2` results in 6.24 k allocations.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [September 4, 2017, 4:19pm UTC](https://discourse.julialang.org/t/performance-regression/5709/5 "2017-09-04T16:19:34Z")

</div>

Just compilation

---

<div class="post-metadata">

**Author:** ![Chong\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chong_wang/32/20307_2.png) [@Chong\_Wang](https://discourse.julialang.org/u/Chong_Wang)\
**Post date:** [September 4, 2017, 5:32pm UTC](https://discourse.julialang.org/t/performance-regression/5709/6 "2017-09-04T17:32:42Z")

</div>

> [@yuyichao](#):
>
> Just compilation

I don’t think so:

```julia
julia> @time [1,2,3] .== 2
  1.098644 seconds (126.88 k allocations: 6.651 MiB)
3-element BitArray{1}:
 false
  true
 false

julia> @time [1,2,3] .== 2
  0.022890 seconds (6.25 k allocations: 344.973 KiB)
3-element BitArray{1}:
 false
  true
 false

julia> @time [1,2,3] .== 2
  0.033313 seconds (6.25 k allocations: 345.020 KiB)
3-element BitArray{1}:
 false
  true
 false

```

Only the first expression needs compilation.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [September 4, 2017, 5:50pm UTC](https://discourse.julialang.org/t/performance-regression/5709/7 "2017-09-04T17:50:43Z")

</div>

No they all need compilation due to the anonymous function generated by the dot syntax.

---

<div class="post-metadata">

**Author:** ![Chong\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chong_wang/32/20307_2.png) [@Chong\_Wang](https://discourse.julialang.org/u/Chong_Wang)\
**Post date:** [September 4, 2017, 5:54pm UTC](https://discourse.julialang.org/t/performance-regression/5709/8 "2017-09-04T17:54:33Z")

</div>

Could you expand a little bit?

So dot syntax will generate anomalous function which will be compiled every time? This seems to be a little unacceptable for performance considerations.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [September 4, 2017, 5:57pm UTC](https://discourse.julialang.org/t/performance-regression/5709/9 "2017-09-04T17:57:42Z")

</div>

> [@Chong\_Wang](#):
>
> So dot syntax will generate anomalous function which will be compiled every time? This seems to be a little unacceptable for performance considerations.

All Julia functions will compile the first time. No anomalies there 🙂. The REPL scope is dynamic so it compiles before running each time. That’s why it’s a performance tip to write functions.

[https://docs.julialang.org/en/latest/manual/performance-tips/](https://docs.julialang.org/en/latest/manual/performance-tips/)

---

<div class="post-metadata">

**Author:** ![Chong\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chong_wang/32/20307_2.png) [@Chong\_Wang](https://discourse.julialang.org/u/Chong_Wang)\
**Post date:** [September 4, 2017, 5:59pm UTC](https://discourse.julialang.org/t/performance-regression/5709/10 "2017-09-04T17:59:51Z")

</div>

Thank you. This is indeed true:

```julia
julia> function test()
                  [1, 2, 3] .== 2
                  return
              end
test (generic function with 1 method)

julia> @time test()
  0.138285 seconds (112.70 k allocations: 5.578 MiB)

julia> @time test()
  0.000008 seconds (9 allocations: 4.594 KiB)

```

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [September 4, 2017, 6:06pm UTC](https://discourse.julialang.org/t/performance-regression/5709/11 "2017-09-04T18:06:07Z")

</div>

> [@Chong\_Wang](#):
>
> So dot syntax will generate anomalous function which will be compiled every time?

Yes

> [@Chong\_Wang](#):
>
> This seems to be a little unacceptable for performance considerations.

but no. It needs recompilation for every appearance in the code, same as everything else so repeated running of the same source code location (not same source code text) does not need recompilation.  
It might be an improvement if the compiler can recognize and cache result that can be reused but it’s unrelated to the runtime performance.
