I’m wondering if you could take advantage of the batch mahalanobius distance 251 that is utilized internally within the multivariate normal.
Without completely understanding the context of your code, I have a sneaky feeling that those repeats should be removed.