Open henry2004y opened 8 months ago
Maybe this is not an issue for performance in our case, but somehow @code_warntype
list it as a warning?
I tried to manually indicate the type:
interpx::ScaledInterpolation{TA, 3, FilledExtrapolation{TA, 3, BSplineInterpolation{TA, 3, Array{TA, 3}, BSpline{Linear{Throw{OnGrid}}}, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}, Base.OneTo{Int64}}}, BSpline{Linear{Throw{OnGrid}}}, TA}, BSpline{Linear{Throw{OnGrid}}}, Tuple{TG, TG, TG}} = scale(itpx, gridx, gridy, gridz)
interpy::ScaledInterpolation{TA, 3, FilledExtrapolation{TA, 3, BSplineInterpolation{TA, 3, Array{TA, 3}, BSpline{Linear{Throw{OnGrid}}}, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}, Base.OneTo{Int64}}}, BSpline{Linear{Throw{OnGrid}}}, TA}, BSpline{Linear{Throw{OnGrid}}}, Tuple{TG, TG, TG}} = scale(itpy, gridx, gridy, gridz)
interpz::ScaledInterpolation{TA, 3, FilledExtrapolation{TA, 3, BSplineInterpolation{TA, 3, Array{TA, 3}, BSpline{Linear{Throw{OnGrid}}}, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}, Base.OneTo{Int64}}}, BSpline{Linear{Throw{OnGrid}}}, TA}, BSpline{Linear{Throw{OnGrid}}}, Tuple{TG, TG, TG}} = scale(itpz, gridx, gridy, gridz)
Now @code_warntype
does not show anything red, but the performance is almost the same:
# Manually mark the types
julia> @benchmark solve($prob_ip, Tsit5(); save_idxs=[1,2,3])
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 18.500 μs … 2.191 ms ┊ GC (min … max): 0.00% … 97.82%
Time (median): 20.900 μs ┊ GC (median): 0.00%
Time (mean ± σ): 23.986 μs ± 36.758 μs ┊ GC (mean ± σ): 2.59% ± 1.69%
▃▆██▇▅▄▁▁▁▄▅▆▆▆▄▂▁▂▂▂▂▁ ▁ ▁ ▂
█████████████████████████▇▆▅▅▅▆███▆▆▅▅▄▄▆▇████▇▆▅▅▅▃▆▇▇█▆▅▅ █
18.5 μs Histogram: log(frequency) by time 47 μs <
Memory estimate: 20.62 KiB, allocs estimate: 129.
# Current master
julia> @benchmark solve($prob_ip, Tsit5(); save_idxs=[1,2,3])
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 19.500 μs … 2.222 ms ┊ GC (min … max): 0.00% … 97.71%
Time (median): 22.800 μs ┊ GC (median): 0.00%
Time (mean ± σ): 25.032 μs ± 37.235 μs ┊ GC (mean ± σ): 2.52% ± 1.69%
▄▇█▇▄▂▁▁▂▄▆▇▆▅▄▂▂▂▂▂▂▁▁▁▁▁▁ ▂
█████████████████████████████▆██▇▇▆▄▆▅▄▅▅▇▇▇▆▅▅▅▄▅▅▄▆▆▅▅▃▅▅ █
19.5 μs Histogram: log(frequency) by time 49.1 μs <
Memory estimate: 20.62 KiB, allocs estimate: 129.
Consider this mixed type field case:
TestParticle.var"#get_field#3"{interpz, interpy, interpx}} where {interpz, interpy, interpx}
indicates type instability.After investigating the issue further, I realized that it is related to the
ScaledInterpolation
type from Interpolations.jl:If I replace
interpx
with a function, it will be type stable. For example, as a minimal demo,This is type stable!.
My feeling is that this issue is related to the captured problem. I have no idea how to solve this...