https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77443
Bug ID: 77443 Summary: Empty initializer on huge object array member slow down the compilation dramatically with -O1 Product: gcc Version: 5.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: gcc at gyoo dot com Target Milestone: --- Adding an empty initializer on a huge array is multiplying the compilation time by about x100 when using -O1: // time g++ -std=c++14 -O1 -Wall initialization.cc class MyObject { public: MyObject() {} }; class MyClassFast { MyObject array[30000]; // ok: fast to build with -O1 }; class MyClassSlow { MyObject array[30000] {}; // problem: super slow to build with -O1 (x100 slower than the fast version) }; int main() { // MyClassFast fast; MyClassSlow slow; } Was working fine with gcc4.9.3. Having this slow behaviour for gcc5.2.0, gcc5.3.0 and gcc5.4.0 Looks like gcc is trying to unroll the constructor for each item of the array. For instance if the constructor of MyObject is marked private instead of public, the compilation will generate 30k (number of elements in the array) compilation error messages.