Skip to content

Performance problems when using broadcasting and logical operators #47493

Closed
@roflmaostc

Description

@roflmaostc

Broadcasting with boolean operators seems to be very slow in some circumstances:

See below one example with Julia 1.8.2:

julia> x = randn((100,));

julia> y = randn((1,100));

julia> @time (x.^2 .< 1) .&& (1 .+ y.^2  .<1);
  0.004369 seconds (144.73 k allocations: 3.005 MiB)

julia> @btime ($x.^2 .< 1) .&& (1 .+ $y.^2  .<1);
  4.009 ms (144713 allocations: 3.00 MiB)

# this works
julia> @btime ($x.^2 .< 1) .&& ($y.^2  .<1);
  2.523 μs (3 allocations: 5.56 KiB)

julia> @btime ($x.^2 .< 1) .|| ($y.^2 .+ 1 .<1);
  2.738 μs (3 allocations: 5.56 KiB)

Metadata

Metadata

Assignees

No one assigned

    Labels

    broadcastApplying a function over a collectionduplicateIndicates similar issues or pull requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions