You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Eagerly evaluate indices in eachindex check (#58054)
This reduces TTFX in `eachindex` calls with multiple arguments, with
minimal impact on performance. Much of the latency comes from the error
path, and specializing it for the common case of 2 arguments helps a lot
with reducing latency. In this, I've also unrolled the `join` in the
error path, and we recursively generate a `LazyString`s instead. This
helps in reducing TTFX for a longer list of arguments.
```julia
julia> a = zeros(2,2);
julia> @time eachindex(a, a);
0.046902 seconds (128.39 k allocations: 6.652 MiB, 99.93% compilation time) # nightly
0.015368 seconds (19.91 k allocations: 1.048 MiB, 99.79% compilation time) # this PR
julia> @Btime eachindex($a, $a, $a, $a, $a, $a, $a, $a);
6.945 ns (0 allocations: 0 bytes) # nightly
6.855 ns (0 allocations: 0 bytes) # this PR
```
This reduces TTFX for a longer list of arguments as well:
```julia
julia> @time eachindex(a, a, a, a, a, a, a, a);
0.052552 seconds (196.87 k allocations: 10.068 MiB, 99.53% compilation time) # nightly
0.043401 seconds (69.13 k allocations: 3.454 MiB, 99.34% compilation time) # this PR
```
For Cartesian indexing,
```julia
julia> a = zeros(2,2);
julia> v = view(a, 1:2, 1:2);
julia> @time eachindex(a, v);
0.051333 seconds (171.34 k allocations: 8.921 MiB, 99.94% compilation time) # nightly
0.016340 seconds (26.95 k allocations: 1.405 MiB, 99.79% compilation time) # this PR
julia> @Btime eachindex($a, $v, $a, $v, $a, $v, $a, $v);
9.339 ns (0 allocations: 0 bytes) # nightly
9.357 ns (0 allocations: 0 bytes) # this PR
```
0 commit comments