tags:

views:

769

answers:

3

We have been looking at g++ versions 3.2.3 and 4.2.4. With 4.2.4, the performance improvements on some of our code base is significant.

I've tried searching the gcc buzilla database to find hints as to what bugs may have had such a dramatic improvement but I didn't find any individual bug that stood out as being a candidate.

Are the improvements the result of many small changes that have slowly had an affect? Or was there say a top 5 set of improvements that may have made a difference?

For some background, our code base does make good use of STL containers and algorithms, as well as C++ features such as the 'inline' keyword.

+1  A: 

In my experience, 3.4 is where the performance basically peaked; 4.2 is actually slower than 3.4 on my project, with 4.3 being the first to roughly equal 3.4's performance. 4.4 is slightly faster than 3.4.

There are a specific few cases I've found where older versions of gcc did some unbelievably retarded things in code--there was a particular function that went from 128 to 21 clocks from 3.4 to 4.3, but that was obviously a special case (it was a short loop where the addition of just a few unnecessary instructions massively hurt performance).

I personally use 3.4 just because it compiles so much faster, making testing much quicker. I also try to avoid the latest versions because they seem to have nasty habits of miscompiling code; --march core2 on recent gcc versions causes segfaults in my program, for example, because it emits autovectorized code that tries to perform aligned accesses on unaligned addresses.

Overall though the differences are rarely large; 3-5% is the absolute most I've seen in terms of performance change.

Now, note this is C; things may be different in C++.

Dark Shikari
Some of our code base has improved more than that. In at least one case things improved so much it has taken us a long time to be happy that there wasn't a bug in the compiler causing a crash.
Richard Corden
Perhaps the changes are less large in my project both because of its widespread use of hand-written assembly and also the amount of effort we've put into finding places the compiler is pessimizing things and fixing them (mostly by modifying the code to coax the compiler into more optimal output).
Dark Shikari
+1  A: 

Streams were very slow in 3.3 and got much faster in 3.4. (message on gcc mailing list) I bet other things improved too.

+1  A: 

I believe the optimizer was completely reworked in the gcc4 series. See this page, for instance, about vectorization:

http://gcc.gnu.org/projects/tree-ssa/vectorization.html

For info, I once did a benchmark of c[i] = a[i] + b[i] with dynamic arrays, static arrays and std::vector and it was the std::vector that was the fastest (w/ gcc 4.1). 30% difference in performance.

rlerallut