Closed dcabecinhas closed 4 years ago
Yeah, this is related to that #9. Honestly, I still have no idea how to get the constants to propagate here. I'm not sure there's even much I can do. It's deep compiler magic.
But there is a workaround. Use s = Val(:a)
. Although for some reason, I only have it set up to work with getindex
and not getproperty
, even though they should be the same. I'll push an update with the new method for getproperty
.
It's kinda a bummer because using Val(:a)
doesn't really help when you need to get properties with dynamically changing symbols since it just kicks the problem over to the Val
call. But I don't really know that it's a solvable problem for that case, since what you would be doing there is inherently type unstable.
With that said, I think I'm going to close this one as a duplicate of #9 because that's really the root of the problem.
Thanks. Val solves my use-case.
Ideally constant-propagation should work but generated functions are not compiler friendly :/
On a related note, I needed to iterate over components of a ComponentVector
today and realized that this was always going to be super slow because the compiler can't infer what comes out of the call keys(ca)
. So now there is a new function in the update I just pushed (a09b9a4, version 0.8.0) called valkeys
that returns Val
-wrapped keys so you can iterate over subcomponents in a fast and type-stable way.
julia> using ComponentArrays, BenchmarkTools
julia> ca = ComponentArray(a=1, b=[1,2,3], c=(a=4,))
ComponentVector{Int64}(a = 1, b = [1, 2, 3], c = (a = 4))
julia> @btime sum(prod($ca[k]) for k in keys($ca))
9.099 μs (7 allocations: 176 bytes)
11
julia> @btime sum(prod($ca[k]) for k in valkeys($ca))
11.511 ns (0 allocations: 0 bytes)
11
I'm trying to index into a CA with a symbol but I get type inference issues.
It looks to me that
f()
andh()
should be equivalent but somehowf()
is not being infered.Is this related with #9? Is there a way around this issue?