User account creation filtered due to spam.

Bug 71995 - ~36% compile-time performance regression for C++ in gcc HEAD vs gcc-6-branch HEAD
Summary: ~36% compile-time performance regression for C++ in gcc HEAD vs gcc-6-branch ...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-25 14:28 UTC by Tom Honermann
Modified: 2016-07-25 14:52 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-07-25 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Honermann 2016-07-25 14:28:35 UTC
A compile-time performance degradation in gcc HEAD (r238592) vs gcc-6-branch HEAD (r238587) was observed while verifying performance improvements for bug 67565.  Though that bug was specific to C++ concepts, the performance regression is not.

In my tests both the gcc and gcc-6-branch compilers were built using the Ubuntu 15.10 x86_64 distribution of gcc 5.2.1:

$ gcc --version
gcc (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010
...

Both gcc builds were configured and built with:
  $ ./configure \
    CC=gcc \
    CXX=g++ \
    --prefix /path/to/install/... \
    --disable-multilib \
    --disable-bootstrap \
    --enable-languages=c,c++
  $ make
  $ make install

The following code was used for testing:

$ cat t.cpp
/*
 * Test adapted from:
 * https://randomascii.wordpress.com/2014/03/10/making-compiles-slow
 */
#if !defined(SCALE_FACTOR)
#define SCALE_FACTOR 23
#endif
template<int R, int N>
struct slow_fibonacci {
    static constexpr int value =
        slow_fibonacci<R, N-1>::value +
        slow_fibonacci<R + (1<<N), N-2>::value;
};
template<int R>
struct slow_fibonacci<R,2> {
    static constexpr int value = 1;
};
template<int R>
struct slow_fibonacci<R,1> {
    static constexpr int value = 1;
};
constexpr int x = slow_fibonacci<0,SCALE_FACTOR>::value;

The test was performed three times at each of three scale factors for each compiler build, the times averaged for each scale factor, and then percentages calculated.

Compile times using the gcc trunk build:
# default SCALE_FACTOR=23
$ time g++ -c -std=c++11 t.cpp
real    0m02.079s  |  real    0m02.089s  |  real    0m02.070s
user    0m02.004s  |  user    0m02.016s  |  user    0m02.000s
sys     0m00.068s  |  sys     0m00.068s  |  sys     0m00.064s
# SCALE_FACTOR=25
$ time g++ -c -std=c++11 -DSCALE_FACTOR=25 t.cpp
real    0m05.401s  |  real    0m05.431s  |  real    0m05.428s
user    0m05.224s  |  user    0m05.272s  |  user    0m05.224s
sys     0m00.172s  |  sys     0m00.156s  |  sys     0m00.204s
# SCALE_FACTOR=27
$ time g++ -c -std=c++11 -DSCALE_FACTOR=27 t.cpp
real    0m14.268s  |  real    0m14.379s  |  real    0m14.654s
user    0m13.912s  |  user    0m13.900s  |  user    0m14.332s
sys     0m00.356s  |  sys     0m00.480s  |  sys     0m00.320s

Compile times using the gcc-6-branch build:
# default SCALE_FACTOR=23
$ time g++ -c -std=c++11 t.cpp
real    0m01.466s  |  real    0m01.432s  |  real    0m01.441s
user    0m01.384s  |  user    0m01.320s  |  user    0m01.356s
sys     0m00.076s  |  sys     0m00.108s  |  sys     0m00.080s
# SCALE_FACTOR=25
$ time g++ -c -std=c++11 -DSCALE_FACTOR=25 t.cpp
real    0m04.076s  |  real    0m04.072s  |  real    0m04.366s
user    0m03.868s  |  user    0m03.920s  |  user    0m04.208s
sys     0m00.204s  |  sys     0m00.148s  |  sys     0m00.152s
# SCALE_FACTOR=27
$ time g++ -c -std=c++11 -DSCALE_FACTOR=27 t.cpp
real    0m10.658s  |  real    0m10.701s  |  real    0m10.779s
user    0m10.096s  |  user    0m10.292s  |  user    0m10.368s
sys     0m00.560s  |  sys     0m00.408s  |  sys     0m00.412s

-------------+---------------+------------------+---------------------+
SCALE_FACTOR | gcc trunk avg | gcc-6-branch avg | % change            |
-------------+---------------+------------------+---------------------+
23           |        2.079s |           1.446s | +43.776% / -30.447% |
25           |        5.420s |           4.171s | +29.945% / -23.044% |
27           |       14.434s |          10.713s | +34.734% / -25.779% |
-------------+---------------+------------------+---------------------+

Averaging the percentages suggests ~36% performance overhead for gcc trunk vs gcc-6-branch.
Comment 1 Andrew Pinski 2016-07-25 14:31:31 UTC
Can you add --enable-checking=release and try again for the trunk?
Comment 2 Tom Honermann 2016-07-25 14:52:43 UTC
(In reply to Andrew Pinski from comment #1)
> Can you add --enable-checking=release and try again for the trunk?

Thanks, that explains it:

Compile times using the gcc trunk build:
# default SCALE_FACTOR=23
$ time g++ -c -std=c++11 t.cpp
real    0m01.427s  |  real    0m01.442s  |  real    0m01.430s
user    0m01.328s  |  user    0m01.384s  |  user    0m01.356s
sys     0m00.092s  |  sys     0m00.052s  |  sys     0m00.068s
# SCALE_FACTOR=25
$ time g++ -c -std=c++11 -DSCALE_FACTOR=25 t.cpp
real    0m03.969s  |  real    0m03.978s  |  real    0m04.008s
user    0m03.816s  |  user    0m03.804s  |  user    0m03.900s
sys     0m00.148s  |  sys     0m00.168s  |  sys     0m00.104s
# SCALE_FACTOR=27
$ time g++ -c -std=c++11 -DSCALE_FACTOR=27 t.cpp
real    0m10.735s  |  real    0m10.757s  |  real    0m10.873s
user    0m10.340s  |  user    0m10.272s  |  user    0m10.420s
sys     0m00.392s  |  sys     0m00.484s  |  sys     0m00.452s

Times are now close enough to gcc-6-branch times that I'm not going to bother calculating percentages.

Closing as resolved/invalid.