Home > Enterprise >  Trying to understand cause of increased compile time going from C 11 to C 14
Trying to understand cause of increased compile time going from C 11 to C 14

Time:12-20

Migrating from C 11 to C 14, I have a source file that usually compiles in ~20s in C 11 mode, but when compiling the same file in C 14 mode the compile time increase to ~340s. That's an increase of about 17 times. The size of the generated object code doubles.

So the clarify my question, I'm trying to understand both what in the code and why the compilers takes that much longer for the same code by changing the -std=c 11/c 14 flag for g .

To make a fair comparison ran the pre-processor over the code (in C 11 mode) and compiled the output with both the C 11 and C 14 flags. E.g.,

g   -E -std=c  11 -g -O2 -o spaghetti.E spaghetti.cpp
g   -c -std=c  11 -g -O2 -o spaghetti-11.o -x c   spaghetti.E
g   -c -std=c  14 -g -O2 -o spaghetti-14.o -x c   spaghetti.E

The file in question does have lots of fixed size arrays of objects in template form like

template<typename T, std::size_t N>
struct Object {
    std::array<T,N> storage{};
    std::vector<T> counters;
};

Symbols involving Object do double when compiled with C 14 over C 11 (among others).

So, what motivates the compiler to take 17 times longer to compile the same file? And what should change to reduce this?

I should note that if I change the Object implementation

template<typename T, std::size_t N>
struct Object {
    std::vector<T> storage{};  // was std::array above, N used in other members
    std::vector<T> counters;
};

It will compile quickly under both C 11 and C 14.

CodePudding user response:

Seems like this is known bug in gcc but isn't getting much traction.
Did you try to switch over to clang ?

PS from comment: Removing the {} behind the storage{} and manually initializing works.

  • Related