xad icon indicating copy to clipboard operation
xad copied to clipboard

huge object file / compile time

Open hiokazaki opened this issue 10 months ago • 1 comments

I have a function with the following signature:

double F(double, double, double, std::array<double, 100>)

and contains about 3000 lines of code, each of which has a few (on average, close to 1) arithmetic operations (only + and *) which take some mix of one of the 103 arguments, one of about 80 temporary (stack) variables, and floating point constants.

In forward mode, the file compiles in a second or two and creates a 50kB object (including debug info etc.)

However, templating the function and attempting to compute its adjoint took clang ~25 minutes to compile (at -O2), and resulted in a 55MB object. Adding #undef XAD_USE_STRONG_INLINE reduced the compile time to ~23 minutes, and the resulting object to ~30MB.

In any case, it seems that both the compile time and object size have increased by about 1000x - is that expected?

I am able to manually break up this function into about 12 smaller functions each emitting a scalar, which are then assembled by another ~100 or so operations into the final scalar. Would that help?

To Reproduce I think that any (non-degenerate) random with this signature and this number of intermediate operations will experience the same issue.

Perhaps a test to validate compile time, object size, and runtime performance scaling as a function of input function size/complexity is worth writing?

Expected behaviour I was expecting compile and runtime to increase by 10x or so, not 1000x.

Environment (please complete the following information):

  • OS: Ubuntu 24.04 LTS
  • Compiler: Clang 20, -O2 -g
  • CMake Configuration (if not default): Not using CMake (just including/linking to xad separately); xad was built with the default CMake configuration.

hiokazaki avatar Feb 07 '25 05:02 hiokazaki

Thanks for opening your first issue here. We'll look into it and get back in due time.

boring-cyborg[bot] avatar Feb 07 '25 05:02 boring-cyborg[bot]

Hi @hiokazaki . We were wondering if you're still facing this issue with the latest version in the main branch? (We've never experienced compile times this long, even with large projects like QuantLib.)

Closing this as we can't reproduce. Feel free to re-open if the problem still persists.