Make building distance marginalization lookup table faster
This MR speeds up making the distance marginalization lookup tables by caching some things. I find that building the table with phase marginalization now takes ~ 30s rather than a few minutes.