Skip to content

Commit

Permalink
Fix performance regression in broadcasting with CartesianIndices (Jul…
Browse files Browse the repository at this point in the history
…iaLang#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 JuliaLang#37829.
This is a workaround on the caller side and does not change
the iteration mechanism itself.


Co-authored-by: Matt Bauman <[email protected]>
Co-authored-by: thofma <[email protected]>
  • Loading branch information
3 people authored and antoine-levitt committed May 9, 2021
1 parent cf42328 commit 3e6e276
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -977,8 +977,10 @@ preprocess_args(dest, args::Tuple{}) = ()
end
end
bc′ = preprocess(dest, bc)
@simd for I in eachindex(bc′)
@inbounds dest[I] = bc′[I]
# Performance may vary depending on whether `@inbounds` is placed outside the
# for loop or not. (cf. https://github.com/JuliaLang/julia/issues/38086)
@inbounds @simd for I in eachindex(bc′)
dest[I] = bc′[I]
end
return dest
end
Expand Down

0 comments on commit 3e6e276

Please sign in to comment.