I want to reduce compile time of a large C++ project. I tried to use precompiled headers, interface and etc. But before I move on, I want to know whether any tool which helps detect why compile time is so long. Somebody suggests pc-lint and I will give a shot. How should I detect unnecessary #include files in a large C++ project? But if there are other tools which analysis compile time and talk about any hints to increase compile speed, let me know. Thanks in advance.
Environment : Microsoft Visual Studio C++ 2008 or 2010.
Why is the Duration of the Compile-time important? It becomes important when it interrupts your ability to work. I mean when you press compile and have to wait 5+ minutes before you can do any testing you will eventually try to optimize the process.
Compiling a C++ file takes a very long time when compared to C# and Java. It takes significantly longer to compile a C++ file than it would to run a normal size Python script.
A compile-time constant is a value that is computed at the compilation-time. Whereas, A runtime constant is a value that is computed only at the time when the program is running. 2. A compile-time constant will have the same value each time when the source code is run.
one approach i like is to review the preprocessor output of a few of your sources -- just read some of it from the compiler's perspective rather than the somewhat abstracted representation that is #inclu
sion. chances are you will find some large chunks of includes/libraries you don't need and weren't necessarily aware of the existence (or need) of the dependency/include. from there, decide which dependencies can be removed. even if your dependencies were all correct, large outputs can also suggest how you might approach dividing larger modules into smaller pieces.
C++ not being modular (yet), compilation bottlenecks are often due to include issues; that is using including too many files when they are not needed. It is also possible that those includes are needed at the moment, but could become superfluous with some simple reengineering.
Since the tool is self-sufficient and documented, let me expand a bit on the review process.
#include
is highly suspicious.If you have trouble knowing what is required, what is not, and how to remove superfluous headers, I recommend a reading of Pimpls - Beauty Marks You Can Depend On; if you do not know what a Pimpl is, read Compilation Firewalls. I would advise cautiousness though, Pimpl has a runtime and maintenance cost, so only use it when it really is necessary. Personally I would absolutely recommend it in the public headers of a library you deliver to 3rd party (ABI compatibility), and otherwise try to avoid it.
If manual inspection is not your forte, you can generate the preprocessor output for each header (do not worry about source files too much), and check the bigger outputs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With