As early as September of this year, one of my projects was faced with the problem of long Compilation Time. I tested the compilation speed yesterday. During the rebuild process using vc7.1,cl.exe, the CPU time was nearly 10 minutes, how big is the entire project? Only over 8000 lines of code (of course, excluding some underlying libraries), while it takes about 3 minutes to rebuild another project with nearly 60 thousand lines of code.
In fact, the reason is also very clear, using too many templates, including a lot of unnecessary header files, and so on.
However, I have never made up my mind to solve this problem. I saw Yun Feng's comments on C ++ pre-compiled header files a few days ago. He mentioned that it is not necessary to study windows for convenience, put everything in windows. h.
I also tried to optimize the object. First, I tried to clear unnecessary header files from the basic header files as much as possible (in my project, there is usually a basedef. h, similar to stdafx of Ms. h), considering some implementation needs, we will put a lot of classes that may be used in basedef. if a file needs to use this class, include the definition header file of this class in the corresponding source file.
In this way, the Compilation speed of my project with over 8000 lines of code is nearly doubled, and the CPU time is more than three minutes.
This is not enough. I carefully observe the VC compilation output and find that a series of files are very slow to compile. (This can only be seen by your eyes. I don't know how to get each file. CPP compilation consumption ......), find the cause of slow compilation (in a header file of include, boost ., also, include the boost header file .....), the next step is to optimize the header file and finally remove the boost header file from the header file.
In this case, I rebuild the project and find that the CPU consumption is only over 50 seconds, which is more than 10 times higher than the initial one ~~~
In fact, the Compilation speed can also be optimized :)