I just found -ftime_report flag, and attempted to use it in order to diagnose why a particular c++ file in my source base is taking many seconds to compile. Unfortunately, it looks like all of the time is spent in the front end, where there are no fine-grained diagnostic metrics. I’m guessing #includes and template instantiation (I’m looking at you, boost) but I want to know for sure.
So to that end, I am thinking of using the llvm::TimePassesIsEnabled flag, and adding timers (llvm::Timer) to each of the different subclasses of clang::FrontEndAction to try and get a bead on where all of the time is going. Does this sound like a good idea? I am afraid that -ftime_report is aiming at the back end (because of the -f prefix), but it would really be great to allow the front ends to contribute to that view.
Thanks in advance for the help!
I don’t think that approach will give you any useful information. You can already use -fsyntax-only to get some idea how much time is spent on lex-parse-sema phase compared to irgen. The former is likely to dominate your compile time. Getting useful timings from that phase is hard. Using -Xclang -print-stats might give you some idea where to look for the source of your problem. Things to explore, size of preprocessed file and where most of the code is coming from, template instantiations, and if I remember correctly Chandler was saying that overload resolution can be slow for functions with large number of overloads (or something like that). Commenting out code in the file would be my next step.
I’ll check these out. I’m also interested in getting detailed metrics for regression purposes.
I realize that there are things I can personally do to speed up the compilation of my project, but in my very casual perusal of clang build times, it looks like C++ is an absolute bear. I don’t understand why objective C and C compile times are in the hundred millisecond range per source file but C++ is commonly in the 3 to 10 second range. Does the C++ language spec really require compilers to do two or three orders of magnitude more work?