static_cast
static_cast

Reputation: 1178

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.

Upvotes: 1

Views: 633

Answers (2)

datenwolf
datenwolf

Reputation: 162164

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.

Upvotes: 2

KevinDTimm
KevinDTimm

Reputation: 14376

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

The first time you compile your build time would probably increase, just because it has to do all that opening of files (and creating the .o(bj)'s). However, each subsequent compile would only have to compile the code that had changed, assuming that you didn't change one of the include (.h) files.

Upvotes: 0

Related Questions