Skip to content
Advertisement

Speeding up gcc compile of a single file

Running RedHat7 w/g++ version 4.8.3 w/j5 arg and o3 optimization.

We currently have a file that is approx 90,000 lines long (a whole bunch of wrapper functions). The compile of this file currently takes between 30 and 40 mins.

What is the best strategy to speed this build time? Would build time increase if it was split between multiple files? Is there a different compiler setting that will help to thread this compile?

Assuming just splitting the file into multiple files would help, but before I go through the work… want community help.

Advertisement

Answer

90000

Yikes!

What is the best strategy to speed this build time?

Split that sucker up into multiple files. Preferrably semantically sorted. Personally I begin feeling uncomfortable when a source file reaches 1k lines. 2k lines definitely feels not right. And 3k is my personal limit.

Would build time increase if it was split between multiple files?

Technically there’s a little overhead launching a compiler. However given enough CPU cores/threads performing a parallel build will easily overcompensate for that and bring total build time down: Run multiple g++ processes in parallel, one for each file. If you’re using make you can do that trivially using the -j option.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement