Open wsshin opened 9 months ago
Related #43333. A workaround (in the meantime) is to define a new function getf(x) = getproperty(x,:f)
and broadcast that instead of getproperty
/getfield
/getindex
directly, although this is a bit more tedious.
Thanks, @mikmoore, I will look into the referenced issue to see if I can fix it. In the meantime, I guess I can use (x->getindex(x, :f)).(s)
following workaround.
Consider a tuple of
NamedTuple
s off::Float64
andi::Int64
(inhomogeneous types):Constructing a tuple with the values of
f
by broadcastinggetindex
with the key:f
is allocating and slow:On the other hand, doing the same thing by broadcasting
getindex
with the index1
(corresponding to the key:f
) is non-allocating and fast:The allocation seems to happen only for
NamedTuple
s composed of inhomogeneous types. For example, a similar case with a homogeneous type such aswhere both fields of the
NamedTuple
areFloat64
, does not allocate even ifgetindex
is used with a key: