Introducing a pre-calculated matrix with all the distances. Still not fast enough