# Drop of performances with Julia 1.6.0 for InterpolationKernels

**URL:** <https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085>\
**Category:** Performance\
**Created:** [March 27, 2021, 4:45pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085 "2021-03-27T16:45:48Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![emmt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emmt/32/5192_2.png) [@emmt](https://discourse.julialang.org/u/emmt)\
**Post date:** [March 29, 2021, 8:08pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/21 "2021-03-29T20:08:38Z")

</div>

I got catch by the following error:

```julia
julia/cli/trampolines/trampolines_x86_64.S:44: Error: no such instruction: `endbr64'

```

and cannot build Julia for commits:

- `2e3364e02f1dc3777926590c5484e7342bc0285d`
- `9528ac2785f214cdc188a835deed3d93e0b012c6`
- `7c17bb361e859aa834034c977ca683a78f17d506`

I will start over…

Is there a way to guess which commit correspond to a given Julia DEV version?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [March 29, 2021, 8:15pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/22 "2021-03-29T20:15:07Z")

</div>

> [@weymouth](#):
>
> However… I have around 30 similar loops in my package. Before I go hunt them all down, can I confirm that this is the “right” way to use `@inbounds @simd` . It seems like I see them scattered around in different places in different code bases.

I don’t think it is an “official way”. The official way would be to have the performance regression properly fixed. I just noticed that this particular rewrite fixed the example you gave and offered it as a potential workaround, while the issue is being looked at more carefully.

---

<div class="post-metadata">

**Author:** ![emmt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emmt/32/5192_2.png) [@emmt](https://discourse.julialang.org/u/emmt)\
**Post date:** [March 29, 2021, 8:19pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/23 "2021-03-29T20:19:34Z")

</div>

This is exaclty what I am doing and it does not fix the issue.

I have pushed [here](https://github.com/emmt/InterpolationKernels.jl/blob/master/test/inline-issue-minimal.jl) the reduced example I am using to track down the issue so you can have alook at the loops.

The narrower `git bisect` range before I could no longer build Julia was (note that the best one was better than Julia-1.5.4):

- the good:

- the bad (260% slower):

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [March 29, 2021, 8:24pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/24 "2021-03-29T20:24:33Z")

</div>

> [@emmt](#):
>
> This is exaclty what I am doing and it does not fix the issue.

You can post the `git bisect log` if you want to “save your progress”.

---

<div class="post-metadata">

**Author:** ![emmt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emmt/32/5192_2.png) [@emmt](https://discourse.julialang.org/u/emmt)\
**Post date:** [March 29, 2021, 8:34pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/25 "2021-03-29T20:34:37Z")

</div>

Oops I have cleaned everything to restart. I’ll give another try tomorrow, it’s late here 😉

---

<div class="post-metadata">

**Author:** ![emmt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emmt/32/5192_2.png) [@emmt](https://discourse.julialang.org/u/emmt)\
**Post date:** [March 29, 2021, 10:39pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/26 "2021-03-29T22:39:20Z")

</div>

OK done, commit [fe1253ee258674844b8c0350deb05018909e823e](https://github.com/JuliaLang/julia/commit/fe1253ee258674844b8c0350deb05018909e823e) is the first bad commit. But looking at what has changed I really do not see why it breaks vectorization.

Here is the output of `git bisect log`:

```julia
git bisect start
# good: [2e3364e02f1dc3777926590c5484e7342bc0285d] [loader]: Re-export symbols for C embedding, rename to `libjulia-internal` (#38160)
git bisect good 2e3364e02f1dc3777926590c5484e7342bc0285d
# good: [7c17bb361e859aa834034c977ca683a78f17d506] Add examples for endswith and startswith (#38255)
git bisect good 7c17bb361e859aa834034c977ca683a78f17d506
# bad: [9631a9fcee01643ccffc8e3c4a7f34b659fa2580] add __CET__ check guards to trampoline assembly (#38683)
git bisect bad 9631a9fcee01643ccffc8e3c4a7f34b659fa2580
# good: [49b8e61a80b8108ca0a23f8075a0d0508b6947c7] Fix out-of-tree compilation of loader library. (#38677)
git bisect good 49b8e61a80b8108ca0a23f8075a0d0508b6947c7
# bad: [8ffcc0ea9274203420e407d0f921cdd4c346fa22] Fix `stdlib/Makefile` rules for JLLs (#38688)
git bisect bad 8ffcc0ea9274203420e407d0f921cdd4c346fa22
# bad: [fe1253ee258674844b8c0350deb05018909e823e] fix #38664, regression in `===` codegen for Bool (#38686)
git bisect bad fe1253ee258674844b8c035

```

For the reccord:

- timings for first version showing the issue:

```julia
Tests with Julia-1.6.0-DEV.1648, T=Float32, n=1000
 ├─ Call spline (1000 times):
 │ ├─ map! ─────────────────────── 195.234 ns (0 allocations: 0 bytes)
 │ ├─ inbounds_map! ────────────── 206.776 ns (0 allocations: 0 bytes)
 │ └─ simd_map! ────────────────── 198.064 ns (0 allocations: 0 bytes)
 └─ Computation of weights with spline (1000 times):
     ├─ compute_weights! ─────────── 1.450 μs (0 allocations: 0 bytes)
     └─ inlined_compute_weights! ─── 1.440 μs (0 allocations: 0 bytes)

```

- timings for the previous version:

```julia
Tests with Julia-1.6.0-DEV.1647, T=Float32, n=1000
 ├─ Call spline (1000 times):
 │ ├─ map! ─────────────────────── 202.012 ns (0 allocations: 0 bytes)
 │ ├─ inbounds_map! ────────────── 201.413 ns (0 allocations: 0 bytes)
 │ └─ simd_map! ────────────────── 193.534 ns (0 allocations: 0 bytes)
 └─ Computation of weights with spline (1000 times):
     ├─ compute_weights! ─────────── 501.495 ns (0 allocations: 0 bytes)
     └─ inlined_compute_weights! ─── 487.655 ns (0 allocations: 0 bytes)

```

---

<div class="post-metadata">

**Author:** ![emmt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emmt/32/5192_2.png) [@emmt](https://discourse.julialang.org/u/emmt)\
**Post date:** [March 30, 2021, 4:43pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/27 "2021-03-30T16:43:33Z")

</div>

Shall I report an issue now?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [March 30, 2021, 4:50pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/28 "2021-03-30T16:50:08Z")

</div>

You can. I am pretty surprised about that bisection but stranger things have happened. Please add enough information so that someone could reproduce the slowdown to confirm the identified commit.

---

<div class="post-metadata">

**Author:** ![emmt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emmt/32/5192_2.png) [@emmt](https://discourse.julialang.org/u/emmt)\
**Post date:** [March 30, 2021, 4:54pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/29 "2021-03-30T16:54:49Z")

</div>

I was also surprised when I looked at the tiny changes implemented by this commit. But I double checked that the previous commit has no such issue and that the issue is there after this commint. I will write a small test case to demonstrate this.

---

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [March 30, 2021, 9:17pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/30 "2021-03-30T21:17:49Z")

</div>

> [@weymouth](#):
>
> @inbounds @simd

I’m not sure if `eachindex(p)` will fulfill your requirements, but it seems as fast as `@inbounds @simd` with `CartesianIndices(p)`.

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [March 30, 2021, 9:35pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/31 "2021-03-30T21:35:50Z")

</div>

Thanks for the thought, but no, this was a contrived example. I only use loops like this instead of broadcasting when I need a sub-range of the array.

---

<div class="post-metadata">

**Author:** ![emmt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emmt/32/5192_2.png) [@emmt](https://discourse.julialang.org/u/emmt)\
**Post date:** [March 31, 2021, 7:35am UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/32 "2021-03-31T07:35:00Z")

</div>

After checking everything, I submitted an issue [#40276](https://github.com/JuliaLang/julia/issues/40276) with a shorter example.

---

<div class="post-metadata">

**Author:** ![jeremiedb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeremiedb/32/29150_2.png) [@jeremiedb](https://discourse.julialang.org/u/jeremiedb)\
**Post date:** [March 31, 2021, 1:28pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/33 "2021-03-31T13:28:01Z")

</div>

In case it’s worth, I also experienced significant slowdown in Julia 1.6 on loops where no tuples were involved:

```julia
using StatsBase:sample
using BenchmarkTools

n_obs = Int(1e6)
n_vars = 100
n_bins = 64
K = 3
𝑖 = collect(1:n_obs)
δ = rand(n_obs, K)
hist = zeros(K, n_bins, n_vars);
X_bin = sample(UInt8.(1:n_bins), n_obs * n_vars);
X_bin = reshape(X_bin, n_obs, n_vars);

function iter_1(X_bin, hist, δ, 𝑖)
    hist .= 0.0
    @inbounds for i in 𝑖
        @inbounds for k in 1:3
            hist[k, X_bin[i,1], 1] += δ[i,k]
        end
    end
end

𝑖_sample = sample(𝑖, Int(n_obs / 2), ordered=true)

```

`  
Julia 1.5.3:

```julia
julia> @btime iter_1($X_bin, $hist, $δ, $𝑖_sample)
  1.224 ms (0 allocations: 0 bytes)

```

Julia 1.6.0:

```julia
julia> @btime iter_1($X_bin, $hist, $δ, $𝑖_sample)
  1.648 ms (0 allocations: 0 bytes)

```

Adding `@simd` into the loop had little or no effect on performance (from 1.22ms to 1.19ms on 1.5.3 and 1.64ms to 1.62ms on 1.6.0)

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [March 31, 2021, 1:39pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/34 "2021-03-31T13:39:34Z")

</div>

Is this is same multi-dimensional array issue @kristoffer.carlsson pointed to previously?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [March 31, 2021, 2:00pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/35 "2021-03-31T14:00:09Z")

</div>

I don’t think so. Looking at it a bit, it might be this change:

[https://github.com/JuliaLang/julia/commit/cd134044fae2934dc5318af6da365109f114d232#diff-7aed4267c497767034ec7a7bb680d6dd2b5ca54cc26e377f174e7a63f66f2034R1064](https://github.com/JuliaLang/julia/commit/cd134044fae2934dc5318af6da365109f114d232#diff-7aed4267c497767034ec7a7bb680d6dd2b5ca54cc26e377f174e7a63f66f2034R1064)

I will verify.

---

<div class="post-metadata">

**Author:** ![jeremiedb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeremiedb/32/29150_2.png) [@jeremiedb](https://discourse.julialang.org/u/jeremiedb)\
**Post date:** [March 31, 2021, 2:01pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/36 "2021-03-31T14:01:45Z")

</div>

From my understanding, it would be different considering that adding the `@inbounds` and/or `@simd` annotations didn’t bring any significant change in performance. For example, the following displays the same slowdown:

```julia
function iter_2(X_bin, hist, δ, 𝑖)
    hist .= 0.0
    @inbounds @simd for i in CartesianIndices(𝑖)
        @inbounds @simd for k in 1:3
            hist[k, X_bin[𝑖[i],1], 1] += δ[𝑖[i],k]
        end
    end
end

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [March 31, 2021, 2:15pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/37 "2021-03-31T14:15:38Z")

</div>

[add a missing propagate\_inbounds to a getindex method by KristofferC · Pull Request #40281 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/40281) should fix it.

---

<div class="post-metadata">

**Author:** ![emmt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emmt/32/5192_2.png) [@emmt](https://discourse.julialang.org/u/emmt)\
**Post date:** [March 31, 2021, 3:39pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/38 "2021-03-31T15:39:47Z")

</div>

I changed the line in `abstractarray.jl` according to your PR (and rebuild the 2 versions of Julia) but it does not change my timings although it does not hurt. Really the only difference between version 1.6.0-DEV.1647 and version 1.6.0-DEV.1648 is the modifications around line 2582 of `src/codegen.cpp`.

In case it may helps to figure out the origin of the issue, I benchmarked a function that combine the computed weights into a single value (instead of storing them in some destination array) and it is as fast with either version of Julia.

```julia
function sum_prod_weights(src::Array{T,1}) where {T<:AbstractFloat}
    s = zero(T)
    @inbounds @simd for i in eachindex(src)
        w1, w2, w3, w4 = compute_weights(src[i])
        s += w1*w2*w3*w4
    end
    return s
end

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [March 31, 2021, 3:43pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/39 "2021-03-31T15:43:11Z")

</div>

Sorry, I was talking about the regression reported in [Drop of performances with Julia 1.6.0 for InterpolationKernels - #33 by jeremiedb](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/33).

---

<div class="post-metadata">

**Author:** ![emmt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emmt/32/5192_2.png) [@emmt](https://discourse.julialang.org/u/emmt)\
**Post date:** [March 31, 2021, 4:35pm UTC](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085/40 "2021-03-31T16:35:41Z")

</div>

OK I understand…

[Previous page](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085.md?page=1)

[Next page](https://discourse.julialang.org/t/drop-of-performances-with-julia-1-6-0-for-interpolationkernels/58085.md?page=3)
