Avoiding type instabilities (with StaticKernels)

This seems like a textbook case for a function barrier. In your case, you can construct the type-unstable Kernel{(r,)} and then pass it into a function which does the actual work.

Your brute-force approach is essentially an attempt to do by hand what the compiler will do for you with a function barrier.

2 Likes