Skip to content

Unexpected broadcast materialization #46081

Open
@chrstphrbrns

Description

@chrstphrbrns

Does f need to materialize the broadcast here?

julia> VERSION
v"1.9.0-DEV.990"

julia> f(a) = length(sin.(a))
f (generic function with 1 method)

julia> g(a) = length(Broadcast.Broadcasted(sin, (a,)))
g (generic function with 1 method)

julia> a = 1:10000000
1:10000000

julia> @btime f(a)
  204.279 ms (3 allocations: 76.29 MiB)
10000000

julia> @btime g(a)
  14.118 ns (1 allocation: 16 bytes)
10000000

julia> @code_lowered f(a)
CodeInfo(
1%1 = Base.broadcasted(Main.sin, a)
│   %2 = Base.materialize(%1)
│   %3 = Main.length(%2)
└──      return %3
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingThis change will break codebroadcastApplying a function over a collection

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions