GCC / Make Build Time优化 [英] GCC/Make Build Time Optimizations

查看:256
本文介绍了GCC / Make Build Time优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有使用gcc和make文件的项目。项目还包含一个大的子项目(SDK)和许多使用该SDK和一些共享框架的相对较小的子项目。

我们使用预编译的头文件,但这只会帮助重新编译更快。

有没有已知的技术和工具可以帮助构建时优化?或者也许你知道一些关于这个或相关主题的文章/资源? 解决方案

您可以从两方面解决问题:重构代码来降低编译器看到的复杂性,或加速编译器的执行。



在不触及代码的情况下,您可以添加更多编译功能。使用ccache避免重新编译已编译的文件,并使用distcc将构建时间分配给更多机器。使用make -j,其中N是核心数+ 1,如果您在本地编译,或者分布式构建的编号更大。该标志将并行运行多个编译器。



重构代码。优先选择包含(简单)的声明。尽可能多地去耦以避免依赖关系(使用PIMPL习惯用法)。

模板实例化非常昂贵,它们会在每个使用它们的编译单元中重新编译。如果你可以重构你的模板来转发声明它们,然后在一个编译单元中实例化它们。


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 framework.

We use precompiled headers, but that helps only for re-compilation to be faster.

Is there any known techniques and tools to help with build-time optimizations? Or maybe you know some articles/resources about this or related topics?

解决方案

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.

这篇关于GCC / Make Build Time优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆