GCC/Make Build Time Optimizations

前端 未结 10 648
鱼传尺愫
鱼传尺愫 2021-02-02 01:22

We have project which uses gcc and make files. Project also contains of one big subproject (SDK) and a lot of relatively small subprojects which use that SDK and some shared fra

相关标签:
10条回答
  • 2021-02-02 01:55

    You can use distcc distributed compiler to reduce the build time if you have access to several machines. Here's an article from from IBM developerWorks related to distcc and how you can use it: http://www.ibm.com/developerworks/linux/library/l-distcc.html

    Another method to reduce build time is to use precompiled headers. Here's a starting point for gcc.

    Also don't forget to use -j when building with make if your machine has more than one cpu/core(2x the number of cores/cpus is just fine).

    0 讨论(0)
  • 2021-02-02 01:56

    From the description of the project I guess that you have one Makefile per directory and are using recursive make a lot. In that case techniques from "Recursive Make Considered Harmful" should help very much.

    0 讨论(0)
  • 2021-02-02 01:57

    Using small files may not always be a good recommendation. A disk have a 32 or 64K min sector size, with a file taking at least a sector. So 1024 files of 3K size (small code inside) will actually take 32 or 64 Meg on disk, instead of the expected 3 meg. 32/64 meg that needs to be read by the drive. If files are dispersed around on the disk you increase read time even more with seek time. This is helped with Disk Cache obviously, to a limit. pre-compiled header can also be of good help alleviating this.

    So with due respect to coding guidelines, there is no point in going out of them just to place each strcuct, typedef or utility class into separate files.

    0 讨论(0)
  • 2021-02-02 02:05

    You can tackle the problem from two sides: refactor the code to reduce the complexity the compiler is seeing, or speed up the compiler execution.

    Without touching the code, you can add more compilation power into it. Use ccache to avoid recompiling files you have already compiled and distcc to distribute the build time among more machines. Use make -j where N is the number of cores+1 if you compile locally, or a bigger number for distributed builds. That flag will run more than one compiler in parallel.

    Refactoring the code. Prefer forward declaration to includes (simple). Decouple as much as you can to avoid dependencies (use the PIMPL idiom).

    Template instantiation is expensive, they are recompiled in every compilation unit that uses them. If you can refactor your templates as to forward declare them and then instantiate them in only one compilation unit.

    0 讨论(0)
  • 2021-02-02 02:06

    If you have multiple computers available gcc is well distributed by distcc.

    You can also use ccache in addition.

    All this works with very little changes of the makefiles.

    0 讨论(0)
  • 2021-02-02 02:12

    http://ccache.samba.org/ speeds up big time.

    I work on a middle sized project, and that's the only thing we do to speed up the compile time.

    0 讨论(0)
提交回复
热议问题