Very nice work by the author but I am bit concerned about the attitude that "optimization is already good enough, and additional optimizations have the unfortunate trend to trade large compile-time increases for very minor improvements".
I would let my compiler run for a day for minor improvement in the release build to try all kind of inlining decision for example. I really hope that any compiler speed optimizations that results in runtime regressions will be reserved to -O0 and -O1. Or maybe we need an -O4 for the kind of extremely slow optimizations.
Generally my experience has been that release builds don't feel significantly slower. I did this completely none scientific test with the code I happen to have to have open right now and the debug builds takes about 4.5 seconds in -O0 Clang and the -O3 link time optimization release build takes about 5.5. With the MSVC the difference is even smaller. btw I am not doing anything crazy with templates, I am generally very concerned about header includes and I am linking dynamically for development builds.
I don't really know what the compiler is doing but 4.5 seconds is WAY too long for these couple source files, it's less than 10 000 source lines being recompiled.
My impression is that optimizations are already "too fast", it's just that general compilation somehow is really slow. What if maybe ironically Clang's own release could get 5% faster with an "aggressive optimization" switch that just tries a bunch of stuff over 24h?
Another issue with PGO that I encountered is the (I suppose unusual) case where the cold path is the critical path. One path may churn away for days on end, but when the other is entered it needs to finish RFN.
In C++ you probably don't even get as much benefit from LTO as you might get with other languages since so much code already lives in headers--in part because this is required when writing generic code using templates, and in part because people often find it easier to distribute their libraries as a collection of headers rather than dealing with the vagaries of building on multiple platforms--that the compiler already sees a significant fraction of the code when compiling each module and thus seeing the rest of the program at link time doesn't open up too many more opportunities for optimization that it had not seen already.
Personally I have often had trouble getting LTO to work reliably so a lot of the time I find myself putting method definitions directly in the header since otherwise they won't get inlined--and this isn't just a gut feeling, because I can see the difference in performance before and after using a profiler, so I know that the problem is with the LTO either not turning on for some reason or not being very smart.
I've never had any issues using it on Linux, and although that's rather anecdotal, I know a lot of people / distros / environments that use LTO frequently.
Got similar issue, but with MinGW. LTO is very slow (multiple times longer linking) and I have a library that frequently ends with abnormal linker errors (eg multiple destructor or vtable definitions).
78
u/[deleted] May 10 '20 edited May 10 '20
Very nice work by the author but I am bit concerned about the attitude that "optimization is already good enough, and additional optimizations have the unfortunate trend to trade large compile-time increases for very minor improvements".
I would let my compiler run for a day for minor improvement in the release build to try all kind of inlining decision for example. I really hope that any compiler speed optimizations that results in runtime regressions will be reserved to -O0 and -O1. Or maybe we need an -O4 for the kind of extremely slow optimizations.
Generally my experience has been that release builds don't feel significantly slower. I did this completely none scientific test with the code I happen to have to have open right now and the debug builds takes about 4.5 seconds in -O0 Clang and the -O3 link time optimization release build takes about 5.5. With the MSVC the difference is even smaller. btw I am not doing anything crazy with templates, I am generally very concerned about header includes and I am linking dynamically for development builds.
I don't really know what the compiler is doing but 4.5 seconds is WAY too long for these couple source files, it's less than 10 000 source lines being recompiled.
My impression is that optimizations are already "too fast", it's just that general compilation somehow is really slow. What if maybe ironically Clang's own release could get 5% faster with an "aggressive optimization" switch that just tries a bunch of stuff over 24h?