Native Plugin - Abnormally long recompile of a library on single file source change


(Adrian Lis) #1

Hi,
Recently I have been seeing long compile times. It started to be annoying at a point I investigated this and it turns out that single source change in one translation unit (.cpp file) causes lots of the source files of a library to be recompiled again and linked that is later on consumed by the executable (I scanned the outputs of a build running --debug switch).

Whatever .cpp file I change I see that this file + 22 other .cpp files (the same ones) are always being recompiled.

This makes compilation times terrible, up to a point that small change takes 1 minute to be recompiled and relinked.

I tried turning off various things in my project, including precompiled headers with no luck.

Example build scan - https://scans.gradle.com/s/au5a4kf6wopfk/ (here I touched 2 .cpp files but that does not matter a lot since again multiple files were recompiled causing long time to compile the library).

Is this normal behavior or my build is doing something bad? How do I even troubleshoot/fix such cases?


(Adrian Lis) #2

After some more debugging I only found out that the incremental compiler actually claims these given files have unresolved includes (why is that? how can I debug what part is problematic?).

I tried to reorganize include, minimize inclusions, move stuff to separate compilation units etc. but I only managed to reduce the number of those mistreated files from 22 to 20.

One example would be inclusion of a header from a prebuilt ‘header’ only library that uses ‘api’ linkage on this dependency - including this header from a .cpp in another library makes this file always recompile (the header is asio.hpp as an example) but not only that as I have more files that are always recompiling.

Any tips would be highly welcomed.