How to Speed Up Compilation Time in Linux

How to speed up compilation time in linux

I use a non-recursive build system based on GNU make and I was wondering how well it scales.

I ran benchmarks on a 6-core Intel CPU with hyper-threading. I measured compile times using -j1 to -j20. For each -j option make ran three times and the shortest time was recorded. Using -j9 results in shortest compile time, 11% better than -j6.

In other words, hyper-threading does help a little, and an optimal formula for Intel processors with hyper-threading is number_of_cores * 1.5:

Sample Image

Chart data is here.

Linux Kernel Compilation speed up command

Well I am not expert but from my experience:

  • set -J parameter same as your processors if you have 8 then make it

    8, you can check from 'cat /proc/cpuinfo'
  • If its virtual machine make sure you have hyper enabled and

    virtual machine is using more than one physical cpu core
  • Dont use toolchain and try to compile at the same target

    architecture (i.e. if its amd64 then compile at amd 64 bit

    machine)

**EDIT:
(Update from Andy comment) Check ccache and how its used in kernel compilation: http://linuxdeveloper.blogspot.de/2012/05/using-ccache-to-speed-up-kernel.html

Additional note: Also make sure you squeeze your CPU enough https://askubuntu.com/questions/523640/how-i-can-disable-cpu-frequency-scaling-and-set-the-system-to-performance

How to speed up g++ compile time (when using a lot of templates)

What has been most useful for me:

  • Build on a RAM filesystem. This is trivial on Linux. You may want to keep a copy of common header files (precompiled or the actual .h files) on the RAM filesystem as well.
  • Precompiled headers. I have one per (major) library (e.g. Boost, Qt, stdlib).
  • Declare instead of include classes where possible. This reduces dependencies, thus reduces the number of files which need to be recompiled when you change a header file.
  • Parallelize make. This usually helps on a case-by-case basis, but I have -j3 globally for make. Make sure your dependency graphs are correct in your Makefile, though, or you may have problems.
  • Use -O0 if you're not testing execution speed or code size (and your computer is fast enough for you not to care much about the (probably small) performance hit).
  • Compile each time you save. Some people don't like this, but it allows you to see errors early and can be done in the background, reducing the time you have to wait when you're done writing and ready to test.


Related Topics



Leave a reply



Submit