https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118168
Bug ID: 118168
Summary: -Wmisleading-indentation causes 10x+ overhead or
higher (visible on mypy-1.13.0)
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: slyfox at gcc dot gnu.org
Target Milestone: ---
Created attachment 59943
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59943&action=edit
a.c.c.xz
I noticed that current gcc-master and gcc-13 takes up to an hour to compile
individual generated C source files from mypy-1.13.0 project. The files are
huge: around 100M if C code and around 2M lines of code.
After a bit of investigation I found that presence of -Wmisleading-indentation
(as part of -Wall) added 10x slow down of the compilation.
I'm attaching 10% of the original preprocessed file. a.c.c is 12MB and 200K
lines of code. a.c.c takes "just" 2 minutes to check:
$ gcc-15 -c a.c.c -o a.o -O0 -g0 -ftime-report -fsyntax-only #
-Wmisleading-indentation
Time variable wall GGC
phase setup : 0.00 ( 0%) 1898k ( 1%)
phase parsing : 0.89 ( 99%) 129M ( 99%)
preprocessing : 0.19 ( 21%) 5919k ( 4%)
lexical analysis : 0.11 ( 12%) 0 ( 0%)
parser (global) : 0.12 ( 14%) 46M ( 35%)
parser struct body : 0.07 ( 8%) 18M ( 14%)
parser function body : 0.40 ( 45%) 57M ( 44%)
TOTAL : 0.89 131M
$ gcc-15 -c a.c.c -o a.o -O0 -g0 -ftime-report -fsyntax-only
-Wmisleading-indentation
Time variable wall GGC
phase setup : 0.00 ( 0%) 1898k ( 1%)
phase parsing : 37.94 (100%) 129M ( 99%)
preprocessing : 0.26 ( 1%) 5919k ( 4%)
lexical analysis : 0.12 ( 0%) 0 ( 0%)
parser (global) : 0.13 ( 0%) 46M ( 35%)
parser struct body : 0.07 ( 0%) 18M ( 14%)
parser function body : 37.34 ( 98%) 57M ( 44%)
parser inl. func. body : 0.01 ( 0%) 521k ( 0%)
TOTAL : 37.94 131M
The difference is 37s vs 0.89s.
`perf report` says that `gcc` spends most of the time fetching lines from
FILE*.
$ perf report
#
89.34% cc1 cc1 [.]
file_cache_slot::get_next_line(char**, long*)
3.45% cc1 libc.so.6 [.] _IO_ferror
1.74% cc1 cc1 [.] ferror@plt
1.18% cc1 cc1 [.]
file_cache_slot::read_line_num(unsigned long, char**, long*)
0.45% cc1 [vdso] [.] __vdso_clock_gettime
0.23% cc1 cc1 [.] pop_scope()
0.09% cc1 cc1 [.] _cpp_lex_direct
As if some caching is lost when resolving line numbers.
$ gcc -v
Using built-in specs.
COLLECT_GCC=/<<NIX>>/gcc-15.0.0/bin/gcc
COLLECT_LTO_WRAPPER=/<<NIX>>/gcc-15.0.0/libexec/gcc/x86_64-unknown-linux-gnu/15.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../source/configure --prefix=/<<NIX>>/gcc-15.0.0
--with-gmp-include=/<<NIX>>/gmp-6.3.0-dev/include
--with-gmp-lib=/<<NIX>>/gmp-6.3.0/lib
--with-mpfr-include=/<<NIX>>/mpfr-4.2.1-dev/include
--with-mpfr-lib=/<<NIX>>/mpfr-4.2.1/lib --with-mpc=/<<NIX>>/libmpc-1.3.1
--with-native-system-header-dir=/<<NIX>>/glibc-2.40-36-dev/include
--with-build-sysroot=/
--with-gxx-include-dir=/<<NIX>>/gcc-15.0.0/include/c++/15.0.0/
--program-prefix= --enable-lto --disable-libstdcxx-pch
--without-included-gettext --with-system-zlib --enable-checking=release
--enable-static --enable-languages=c,c++ --disable-multilib --enable-plugin
--disable-libcc1 --with-isl=/<<NIX>>/isl-0.20 --disable-bootstrap
--build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu
--target=x86_64-unknown-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.0 99999999 (experimental) (GCC)