15

I have built an up-to-date vanilla GCC from svn with these flags:

../configure \  
    --enable-languages=c,c++ \  
    --disable-nls \  
    --enable-multilib \  
    --prefix=/opt/other/gcc-svn \  
    --program-suffix=-svn \  
    --with-system-zlib

First with clang 3.4, then I thought it may be clang's fault (with a grain of salt) and rebuilt GCC once
more with GCC 4.8.1, which led to the exact same result.

The resulting GCC is about 17 seconds slower than GCC 4.8.1 when I try to compile a C++ project with approx. 150k lines of code.

These are the build times I get (-O3):

  • g++ 4.9: 48 seconds
  • g++ 4.8: 31 seconds
  • clang 3.4: 13 seconds

Did I miss a configure flag or is GCC 4.9 really that much slower?!

manlio
  • 18,345
  • 14
  • 76
  • 126
Thomas
  • 3,074
  • 1
  • 25
  • 39
  • 3
    Isn't GCC still in the very early stages of development? I would expect it to speed up significantly as it nears release. – Chad Jan 09 '14 at 19:30
  • What optimisations did GCC 4.9 add? Those are likely candidates for causing the slow-down. And as Chad noted, that might change. – Konrad Rudolph Jan 09 '14 at 19:34
  • 1
    @Chad: I wouldn't say early, it's been quite a while since GCC 4.8 has been released. http://gcc.gnu.org/gcc-4.8/ (march). – Thomas Jan 09 '14 at 19:51
  • @Konrad Rudolph: I don't think they would add optimizations which slow down the compiler that much (or at least not with the usual -O3, just tested -O1 which also got a _lot_ slower). – Thomas Jan 09 '14 at 19:52
  • Both with C++ enabled? (4.9 might do it by default, while 4.8 might not?) – Yakk - Adam Nevraumont Jan 09 '14 at 20:05
  • @Yakk: Looks like 4.8 also requires a C++ compiler for bootstraping (using my dist's default gcc installation): http://gcc.gnu.org/gcc-4.8/changes.html, if it's what you mean. – Thomas Jan 09 '14 at 20:14
  • @Thomas no, I'm talking about what settings gcc uses by default in compiling the project. If 4.9 is compiling with different settings by default (say, C++11 enabled), it could explain why it is slower. – Yakk - Adam Nevraumont Jan 09 '14 at 20:25
  • @Yakk: Oh, I am passing `-std=gnu++11` to both, 4.8 and 4.9, and I've heard they are never gonna make C++11 default, because it would break some existing code (`auto` keyword and so on). – Thomas Jan 09 '14 at 20:30
  • It looks like it is the code-generator itself which causes the massive slow down because `-fsyntax-only` is nearly equally fast as with 4.8. Let's hope they can get this fixed until the release... – Thomas Jan 09 '14 at 20:46
  • It's a different compiler; it comes with its own (more complete) libstdc++, so the code you are compiling might even be different (if you use the standard library); it has different optimization algorithms. There are plenty of reasons for it to perform differently (slowly, since it's doing more work). Without even seeing what the code being compiled does, how can anyone give an objective answer? – DanielKO Jan 09 '14 at 22:00
  • 2
    @Thomas please try [`-ftime-report`](http://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html) and compare for gcc 4.8 and 4.9. It may give insights as to what's going on. – Ali Jan 09 '14 at 22:01
  • 5
    @Ali: Thanks a lot for your comment, with `-ftime-report` GCC printed '`Extra diagnostic checks enabled; compiler may run slowly. Configure with --enable-checking=release to disable checks.`'. Will give it a try. – Thomas Jan 09 '14 at 22:11
  • g++ 4.9: http://pastebin.com/raw.php?i=ekWV4nUg, g++ 4.8: http://pastebin.com/raw.php?i=KZ7pPh7i – Thomas Jan 09 '14 at 22:24
  • 3
    @Ali: `--enable-checking=release` fixed it, now the same project builds in about 30 seconds with g++ trunk. Can you please post it as an answer, so I can accept it? – Thomas Jan 09 '14 at 22:54

1 Answers1

29

If the compiler is slower than expected, passing the -ftime-report flag can help figuring out what's going on.

Luckily, it also helped in this case: With -ftime-report GCC printed

'Extra diagnostic checks enabled; compiler may run slowly. Configure with --enable-checking=release to disable checks.'

Thomas has rebuilt the compiler from source accordingly and the problem is gone!

Rakete1111
  • 47,013
  • 16
  • 123
  • 162
Ali
  • 56,466
  • 29
  • 168
  • 265
  • 1
    A useful thing to know. Nice work gentlemen! This is only disabled by default for snapshots right? – Brett Hale Jan 09 '14 at 23:09
  • @BrettHale Yes, I believe so. But you can easily figure out whether your compiler is affected by passing the `-ftime-report` flag to your compiler ;) By the way, clang also builds with Asserts+Debug enabled if you check it out from the repo and just do a default build. I think it is reasonable to do so for snapshots. – Ali Jan 10 '14 at 00:30