# Unrolling loops over tuples - why so hard?

**URL:** https://discourse.julialang.org/t/unrolling-loops-over-tuples-why-so-hard/103428
**Category:** Performance
**Tags:** tuple, unrolling
**Created:** [August 31, 2023, 10:25pm UTC](https://discourse.julialang.org/t/unrolling-loops-over-tuples-why-so-hard/103428 "2023-08-31T22:25:53Z")
**Posts on this page:** 1
**Showing post:** 15

<div class="post-metadata">

### Author: ![matthias314](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@matthias314](https://discourse.julialang.org/u/matthias314)
#### Post date: [September 10, 2023, 10:58pm UTC](https://discourse.julialang.org/t/unrolling-loops-over-tuples-why-so-hard/103428/15 "2023-09-10T22:58:11Z")

</div>

Since no-one has mentioned it so far, I just want to add that `reduce` and other folding operations unroll the implicit loop over a tuple:

```julia
julia> @code_typed reduce(+, args)
CodeInfo(
1 ─ %1 = Core.getfield(itr, 1)::UInt8
│ %2 = Core.getfield(itr, 2)::Int16
│ %3 = Core.getfield(itr, 3)::UInt32
│ %4 = Core.getfield(itr, 4)::Float32
│ %5 = Core.getfield(itr, 5)::Float64
│ %6 = Core.zext_int(Core.Int16, %1)::Int16
│ %7 = Base.add_int(%6, %2)::Int16
│ %8 = Base.sext_int(UInt32, %7)::UInt32
│ %9 = Base.add_int(%8, %3)::UInt32
│ %10 = Base.uitofp(Float32, %9)::Float32
│ %11 = Base.add_float(%10, %4)::Float32
│ %12 = Base.fpext(Base.Float64, %11)::Float64
│ %13 = Base.add_float(%12, %5)::Float64
└── return %13
) => Float64

```

---

_[View the full topic](https://discourse.julialang.org/t/unrolling-loops-over-tuples-why-so-hard/103428)._
