如何提高大型工程的编译速度?

这里的大型工程是指源代码个数超过1万以上的c/c++或者java的混合工程,而android AOSP就是这样一个很贴切的例子。android整个系统的编译非常耗时,动辄一个小时以上,搜索了一下关于提高编译速度的相关资料,可以从以下几方面入手。

  • 提高编译系统的硬件能力
    首先能够想到的肯定是提高编译机的硬件能力,例如cpu、内存、硬盘等。

  • 使用ccache
    ccache is a compiler cache. It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again. Supported languages are C, C++, Objective-C and Objective-C++.
    ccache适用于c、c++、Objective-C 、Objective-C++。

  • 更换Java编译器
    例如Eclipse compiler的速度就要快于oracle的javac,下面的文章介绍了javac和eclipse中java编译器的不同点。
    http://stackoverflow.com/questions/3061654/what-is-the-difference-between-javac-and-the-eclipse-compiler

  • 分布式编译
    c/c++等语言可以使用distcc工具进行分布式编译,
    distributed builds for C, C++ and Objective C。
    https://github.com/distcc
    但是目前还没找到活跃的Java相关的分布式编译工具,有人写了个类似的Java分布式编译的工具,可以借鉴该思想。
    http://www.pointdefence.net/jarc/index.html
    Hello, I have attempted to build a remote compiler based on standard Java SE API [>1.6] http://java.sun.com/javase/6/docs/api/ and RMI, primarily to experiment with these technologies, and secondly to see if I could move the burden of CPU intensive operation of compilation away from the development environment or production hosts (in the case of dynamic compilation). Pushing the compilation task across the network may reduce negative impact on other applications i.e. free up computation power for more important tasks, checking email, performing business logic and serving other clients for example.

在我认为,像AOSP这种动辄数万个c、java源文件的工程中,编译速度主要和AOSP系统编译架构、磁盘IO、编译机硬件处理能力(cpu/ram等)有很大的关系。在单台机器硬件瓶颈或者考虑成本的情况下,分布式编译应该还是可以相应提高编译速度的,特别是如果在局域网中搭建分布式环境,这时网络延时会比较小,分布式数据的传输延时较小,将整个系统的编译任务分布到多个局域网中的编译机上进行编译会大大提高编译的速度。

具体能够减少多少的编译时间,还待后续的研究。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值