Skip to content

Commit cf0c32f

Browse files
kimikagembaumanthofma
authored andcommitted
Fix performance regression in broadcasting with CartesianIndices (#39333)
* Fix performance regression in broadcasting with CartesianIndices This avoids the boundary check due to a change in the implementation of iteration using `CartecianIndices` in PR #37829. This is a workaround on the caller side and does not change the iteration mechanism itself. Co-authored-by: Matt Bauman <mbauman@gmail.com> Co-authored-by: thofma <thofma@gmail.com> (cherry picked from commit a4cd68c)
1 parent 37305d7 commit cf0c32f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

base/broadcast.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,8 +978,10 @@ preprocess_args(dest, args::Tuple{}) = ()
978978
end
979979
end
980980
bc′ = preprocess(dest, bc)
981-
@simd for I in eachindex(bc′)
982-
@inbounds dest[I] = bc′[I]
981+
# Performance may vary depending on whether `@inbounds` is placed outside the
982+
# for loop or not. (cf. https://github.com/JuliaLang/julia/issues/38086)
983+
@inbounds @simd for I in eachindex(bc′)
984+
dest[I] = bc′[I]
983985
end
984986
return dest
985987
end

0 commit comments

Comments
 (0)