https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86091

            Bug ID: 86091
           Summary: [fold expression] Slow compile time and high memory
                    usage compared to initializer_list folds
           Product: gcc
           Version: 7.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vasili.burdo at gmail dot com
  Target Milestone: ---

Created attachment 44253
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44253&action=edit
Test program

Consider test program in attachment.
This program tries to validate large (1000 entries) user-defined literal using
c++17 fold expression - and its compile time is VERY slow.
For c++ version earlier than c++17 fold is emulated using intitalizer_list - in
this case compile time is MUCH better.

Please note execution times and memory usage reported by `time' in invocation
examples below.

When compiled with command line (buggy behavior) 
"/usr/bin/time -v g++ -std=gnu++1z -Wall -Wextra -D BUG test.cpp" its output
is:
----------------------------------------------------------
        Command being timed: "g++ -std=gnu++1z -Wall -Wextra -D BUG test.cpp"
        User time (seconds): 30.40
        System time (seconds): 1.72
        Percent of CPU this job got: 99%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:32.12
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 6760368
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 1690547
        Voluntary context switches: 13
        Involuntary context switches: 42
        Swaps: 0
        File system inputs: 0
        File system outputs: 136
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0
----------------------------------------------------------

When compiled with command line (no `BUG' defined) 
"/usr/bin/time -v g++ -std=gnu++1z -Wall -Wextra test.cpp" its output is:
----------------------------------------------------------
        Command being timed: "g++ -std=gnu++1z -Wall -Wextra test.cpp"
        User time (seconds): 0.14
        System time (seconds): 0.02
        Percent of CPU this job got: 99%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.16
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 47784
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 13603
        Voluntary context switches: 12
        Involuntary context switches: 5
        Swaps: 0
        File system inputs: 0
        File system outputs: 880
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0
----------------------------------------------------------

Compiler version (official Ubuntu GCC):
----------------------------------------------------------
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.3.0-16ubuntu3'
--with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-major-version-only --with-as=/usr/bin/x86_64-linux-gnu-as
--with-ld=/usr/bin/x86_64-linux-gnu-ld --program-suffix=-7
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie
--with-system-zlib --with-target-system-zlib --enable-objc-gc=auto
--enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3) 
----------------------------------------------------------

OS Version:
----------------------------------------------------------
Linux epbyminw0019t2 4.15.0-22-generic #24-Ubuntu SMP Wed May 16 12:15:17 UTC
2018 x86_64 x86_64 x86_64 GNU/Linux
----------------------------------------------------------

I tried multiple GCC versions starting from 5.3 to 8.0.0 on Ubuntu and Windows
(MINGW) all of them have the same problem.

Reply via email to