Speed up a derivative calculation?

Try using @code_warntype to spot type instabilities. The quoted code is a hint at a likely instability.