performancelinkerc++17libtorch

Why might the single act of linking against a library drastically degrade the runtime of a C++ program?


I have a reasonably large C++ project, and I would like to add LibTorch as a dependency. I've downloaded the pre-built LibTorch libraries from the website, and updated my CMakeFile as follows:

find_package(Torch ${PYTORCH_VERSION} REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
target_link_libraries(App ${TORCH_LIBRARIES})

I make no other changes to my project. However, when I rebuild the project suddenly all my unit tests each take approximately 100 times as long to execute. None of the other libraries linked against cause this problem, so I don't know how to even start debugging it.

I guess my question is: in general terms, why might simply linking against a library drastically degrade the runtime of a C++ program?

(of course if anyone knows why LibTorch in particular might cause this problem, that would be very welcome indeed!)


Solution

  • Most likely the library includes some static C++ objects with long-running constructors.