rmjarvis / TreeCorr

Code for efficiently computing 2-point and 3-point correlation functions. For documentation, go to
http://rmjarvis.github.io/TreeCorr/
Other
97 stars 37 forks source link

More refactoring to reduce compiled library size. #157

Closed rmjarvis closed 1 year ago

rmjarvis commented 1 year ago

Before adding more data type combinations (e.g. NGG, NNG) or new data types (e.g. spin-1 and spin-4 quantities), I wanted to do some refactoring of the internal structure in the C++ code.

Currently, the code uses template meta-programming to have the compiler generate different functions for the different metrics, bin types, data types, and more. These make the code faster by avoiding if statements in high-traffic functions by determining the branching at compile time rather than run time. However, they also make the compiled library fairly large, since the core functions have up to 6 template parameters, each of which takes on from 3 to 6 values. So that's a lot of combinations, which are about to increase when I add more types of correlations.

I realized that this wasn't really necessary -- that I could refactor the code to remove the data type parameters from the list of template parameters in the core tree processing functions and use virtual functions to get the right function for the final step where the data types actually matter.

This reduced the compiled library size by more than a factor of 2. And moreover, with the new code structure, when I add additional data types, it won't cause the library size to blow up nearly as much as it would have.