# Union splitting not working in Julia 1.10?

**URL:** <https://discourse.julialang.org/t/union-splitting-not-working-in-julia-1-10/108710>\
**Category:** Performance\
**Created:** [January 11, 2024, 11:29pm UTC](https://discourse.julialang.org/t/union-splitting-not-working-in-julia-1-10/108710 "2024-01-11T23:29:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)\
**Post date:** [January 11, 2024, 11:29pm UTC](https://discourse.julialang.org/t/union-splitting-not-working-in-julia-1-10/108710/1 "2024-01-11T23:29:41Z")

</div>

I’m getting the following results under 1.10:

```julia
julia> using BenchmarkTools

julia> x = rand(10_000);

julia> function badsum(x)
               s = 0
               for t in x
                   s += t
               end
               return s
           end
badsum (generic function with 1 method)

julia> function goodsum(x)
           s = zero(eltype(x))
           for t in x
               s += t
           end
           return s
       end
goodsum (generic function with 1 method)

julia> @btime goodsum($x)
  8.667 μs (0 allocations: 0 bytes)
5011.233699365655

julia> @btime badsum($x)
  17.400 μs (0 allocations: 0 bytes)
5011.233699365655

julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39 (2023-12-25 18:01 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
  Threads: 1 on 8 virtual cores
Environment:
  JULIA_EDITOR = runemacs.exe

```

`badsum` takes twice as long, even though in Julia 1.9.4 on the same machine the two functions are equally fast (8.7 μs), as expected due to union splitting.

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [January 12, 2024, 6:45am UTC](https://discourse.julialang.org/t/union-splitting-not-working-in-julia-1-10/108710/2 "2024-01-12T06:45:19Z")

</div>

This seems fixed on master again, so worth looking into what fixed this.

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [January 12, 2024, 10:22am UTC](https://discourse.julialang.org/t/union-splitting-not-working-in-julia-1-10/108710/3 "2024-01-12T10:22:21Z")

</div>

I took this opportunity to learn how `git bisect` works 🙂 It points me to this commit:

> <https://github.com/JuliaLang/julia/commit/8e4221f676cc0cc242b93389b2f65084931e581c>
>
> Current Status:
> 
> \- \[x\] Self test of Julia-GCChecker :: \`MissingRoots.c\`
> \- \[x\]… ASAN: \`error: \<unknown\>:0: Cannot represent a difference across
> sections\`
> \- \[x\] x86\_64-apple-darwin fails in ranges 
> \- \[x\] llvmpasses
> 
> \---------
> 
> Co-authored-by: Gabriel Baraldi \<baraldigabriel@gmail.com\>
> Co-authored-by: Prem Chintalapudi \<prem.chintalapudi@gmail.com\>
> Co-authored-by: Jameson Nash \<vtjnash@gmail.com\>
> Co-authored-by: Tim Besard \<tim.besard@gmail.com\>

I don’t think this can be backported easily as it sounds like a rather complex commit 😅 But I really have no idea. How should we proceed with this information?

Maybe we can see what broke it and fix it that way? I’ll bisect again and search commit introducing the regression.

> **Test script**
>
> ```julia
> #!/bin/bash
> #=
> make -s clean >> ~/buildlogs_julia.txt
> make -s -C deps uninstall >> ~/buildlogs_julia.txt
> if make -s -j 8 >> ~/buildlogs_julia.txt ; then
> echo "build success"
> else
> echo "build failure"
> exit 125
> fi
> exec ~/julia/bisect/julia/julia --startup=no $0
> =#
> using BenchmarkTools
> x = rand(10_000);
> function badsum(x)
> s = 0
> for t in x
> s += t
> end
> return s
> end
> 
> function goodsum(x)
> s = zero(eltype(x))
> for t in x
> s += t
> end
> return s
> end
> 
> bbad = @benchmark badsum($x)
> bgood = @benchmark goodsum($x)
> badmean = mean(bbad.times)
> goodmean = mean(bgood.times)
> @info "" goodmean badmean
> # we search for the commit that fixes the performance
> # so in git bisect lingo:
> # performance difference -> normal -> good
> # no performance difference -> "bug" -> bad
> if 1.25*goodmean < badmean
> @info "GOOD COMMIT (performance difference)"
> exit(0) # good commit
> else
> @info "BAD COMMIT (no performance difference)"
> exit(1) # bad commit
> end
> 
> ```

> **git bisect command**
>
> ```julia
> $ git bisect start HEAD v1.10.0
> $ git bisect run ../script.jl
> ...
> 8e4221f676cc0cc242b93389b2f65084931e581c is the first bad commit
> 
> ```

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [January 12, 2024, 10:27am UTC](https://discourse.julialang.org/t/union-splitting-not-working-in-julia-1-10/108710/4 "2024-01-12T10:27:16Z")

</div>

This appears to be the commit that fixes that issue. If you have the time, you also check which was the first “bad” commit that led to the regression?

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [January 12, 2024, 11:22am UTC](https://discourse.julialang.org/t/union-splitting-not-working-in-julia-1-10/108710/5 "2024-01-12T11:22:29Z")

</div>

> [@abraemer](#):
>
> I don’t think this can be backported easily as it sounds like a rather complex commit 😅 But I really have no idea. How should we proceed with this information?

Upgrade of LLVM will never be backported.

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [January 12, 2024, 11:59am UTC](https://discourse.julialang.org/t/union-splitting-not-working-in-julia-1-10/108710/6 "2024-01-12T11:59:15Z")

</div>

Bisection points to

> <https://github.com/JuliaLang/julia/commit/4200aa9471bbe3af448931eb2b35fcfee0550e24>
>
> Unify and split the pass pipeline

That makes sense I guess but also looks like a complicated commit.

> [@giordano](#):
>
> Upgrade of LLVM will never be backported.

That’s what I thought. So we need a different fix for 1.10.

---

<div class="post-metadata">

**Author:** ![kpamnany](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kpamnany/32/206168_2.png) [@kpamnany](https://discourse.julialang.org/u/kpamnany)\
**Post date:** [January 12, 2024, 3:14pm UTC](https://discourse.julialang.org/t/union-splitting-not-working-in-julia-1-10/108710/7 "2024-01-12T15:14:21Z")

</div>

@PeterSimon: is there an issue for this? If not, would you please open one?

---

<div class="post-metadata">

**Author:** ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)\
**Post date:** [January 12, 2024, 4:20pm UTC](https://discourse.julialang.org/t/union-splitting-not-working-in-julia-1-10/108710/8 "2024-01-12T16:20:51Z")

</div>

Issue created: [Union splitting regression in 1.10 · Issue #52875 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/52875#issue-2079215317)
