# Performance of Interpolations in Modeling toolkit

Hello,

I’m trying to create a lookup table function in modeling toolkit, for that I used Interpolations.jl to make an interpolation between elements of a table, my code is working perfectly fine but the problem is in the performance and the number of allocations, I used the profiler to find the source of the problem, and it’s in the interpolation,

function interpolateMatrix(X1,X2,Data::Matrix{Float64},bp1::Vector{Float64},bp2::Vector{Float64})
interpolator = linear_interpolation((bp1::Vector{Float64}, bp2::Vector{Float64}), Data::Matrix{Float64},extrapolation_bc=Flat())
return interpolator(X1,X2)
end
@register interpolateMatrix(X1::Float64,X2::Num,Data::Matrix{Float64},bp1::Vector{Float64},bp2::Vector{Float64})::Float64
function LookupTable1D(;name)
@parameters lintype::Float64
@variables u(t)=0 y(t)=0
eqs = [scalarize(y ~ interpolateMatrix(lintype,u,Tabledata::Matrix{Float64},bp1::Vector{Float64},bp2::Vector{Float64}));
]
ODESystem(eqs;name)
end

when I test the interpolation function alone it’s fast

When I use it in a modeling toolkit system it’s very slow,

If you can give me advice or solutions for this problem I’ll be thankful.
here is the data I’m using ;

Tabledata1 =[[0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10];
[0 0.635 1.27 1.9 2.54 3.175 3.81 4.445 5.08 5.715 6.35 6.975 7.514 8.03 8.54 8.995 9.35 9.599 9.762 9.896 10];
[0 0.6 1.2 1.8 2.4 3 3.6 4.2 4.8 5.4 6 6.6 7.155 7.639 8.109 8.532 8.916 9.292 9.621 9.827 9.98];
[0 0.8 1.6 2.4 3.2 4 4.8 5.6 6.393 6.985 7.508 8.012 8.376 8.661 8.929 9.19 9.433 9.632 9.79 9.93 10];
[0 0.7 1.4 2.1 2.8 3.5 4.2 4.9 5.557 6.147 6.728 7.306 7.869 8.29 8.661 9.02 9.369 9.637 9.807 9.944 10]]
bp111 =[0.0,1.0,2.0,3.0,4.0]
bp21 =[0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,7.5,8,8.5,9,9.5,10]
lintype = 3.0

It needs work. It’s just not good right now and we know it . We also know why though, and so it’s on the roadmap for solving in the near future.