Skip to content

Commit

Permalink
Fix performance regression in broadcasting with CartesianIndices (#39333
Browse files Browse the repository at this point in the history
)

* 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 <[email protected]>
Co-authored-by: thofma <[email protected]>
  • Loading branch information
3 people authored Jan 21, 2021
1 parent 9af1877 commit a4cd68c
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 a4cd68c

Please sign in to comment.