Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

File takes 8s to compiled with clang but only 74ms to compile with gcc #10905

Open Quuxplusone opened 13 years ago

Quuxplusone commented 13 years ago
Bugzilla Link PR10651
Status NEW
Importance P normal
Reported by stark@mit.edu
Reported on 2011-08-13 06:44:52 -0700
Last modified on 2019-12-24 23:43:37 -0800
Version trunk
Hardware PC Linux
CC anton@korobeynikov.info, dgregor@apple.com, efriedma@quicinc.com, jryans@gmail.com, kremenek@apple.com, llvm-bugs@lists.llvm.org, rafael@espindo.la, vleschuk@gmail.com, wendling@apple.com, yuanfang.chen@sony.com
Fixed by commit(s)
Attachments syscache-preprocessed.c (375133 bytes, text/plain)
Blocks
Blocked by
See also
The build times for Postgres are still slower with clang than gcc. On my
machine Postgres builds in about 90s with gcc but takes nearly 4 minutes with
clang. There is no longer a single offending file but there are a bunch of
files that seem to take 5-8s with clang even though they don't take
particularly long with gcc. This is true even with -O0.

This is the current worst offender but there are 17 files that take 10 times as
long or more to build with clang as gcc.

These times are after running the two commands repeatedly:

$ time gcc -c syscache-preprocessed.c

real    0m0.074s
user    0m0.050s
sys     0m0.040s

$ time clang -c syscache-preprocessed.c

real    0m7.742s
user    0m7.700s
sys     0m0.040s
Quuxplusone commented 13 years ago

Attached syscache-preprocessed.c (375133 bytes, text/plain): Preprocessed syscache.c C source file from Postgres source

Quuxplusone commented 13 years ago

Sanity test: Are you using a debug build of clang? Or is it a release build without assertions?

Quuxplusone commented 13 years ago
(In reply to comment #2)
> Sanity test: Are you using a debug build of clang? Or is it a release build
> without assertions?

Sorry I should have mentioned that. It's a Release+Assertions build built with
clang.
Quuxplusone commented 13 years ago
(In reply to comment #3)
> (In reply to comment #2)
> > Sanity test: Are you using a debug build of clang? Or is it a release build
> > without assertions?
>
> Sorry I should have mentioned that. It's a Release+Assertions build built with
> clang.

Hm, it seems like a significant portion of the time is indeed the assertions. I
rebuilt without assertions and it's only 30x slower than gcc now:

$ time clang -c syscache-preprocessed.c

real    0m2.237s
user    0m2.220s
sys     0m0.020s
$ time gcc -c syscache-preprocessed.c

real    0m0.073s
user    0m0.060s
sys     0m0.020s
Quuxplusone commented 13 years ago
This looks like a front-end slowdown:

$ clang -c syscache-preprocessed.c -ftime-report
...

===-------------------------------------------------------------------------===
                         Miscellaneous Ungrouped Timers
===-------------------------------------------------------------------------===

   ---User Time---   --System Time--   --User+System--   ---Wall Time---  --- Name ---
   5.4148 ( 99.6%)   0.0195 ( 64.4%)   5.4342 ( 99.4%)   5.4344 ( 99.4%)  Clang front-end timer
   0.0096 (  0.2%)   0.0077 ( 25.5%)   0.0173 (  0.3%)   0.0183 (  0.3%)  LLVM IR Generation Time
   0.0097 (  0.2%)   0.0031 ( 10.2%)   0.0128 (  0.2%)   0.0128 (  0.2%)  Code Generation Time
   5.4341 (100.0%)   0.0302 (100.0%)   5.4643 (100.0%)   5.4655 (100.0%)  Total
Quuxplusone commented 13 years ago

This might be the revenge of insanely long redeclaration chains; it's happened before with Postgres.

Quuxplusone commented 13 years ago

This is also rdar://problem/9907018

Quuxplusone commented 12 years ago
The problem here is that Postgres has a huge number of declarations of the same
entity, e.g,

extern int no_such_declaration;
extern int no_such_declaration;
extern int no_such_declaration;
extern int no_such_declaration;
extern int no_such_declaration;
extern int no_such_declaration;
// repeated a few thousand times

We invalidate and then recompute the cached linked with each redeclaration, and
recomputing that linkage walks the entire list of previous declarations, which
leads to quadratic behavior.
Quuxplusone commented 11 years ago

Assigning to myself for now.

I find this bug amusing and I am trying to code a solution. No promises it will actually work.

Quuxplusone commented 9 years ago
This is much better these days, but we still have a super liner behaviour when
linking decls.

The testcase reduces to

#define M1  extern int a;
#define M2  M1  M1
#define M3  M2  M2
#define M4  M3  M3
#define M5  M4  M4
#define M6  M5  M5
#define M7  M6  M6
#define M8  M7  M7
#define M9  M8  M8
#define M10 M9  M9
#define M11 M10 M10
#define M12 M11 M11
#define M13 M12 M12
#define M14 M13 M13
#define M15 M14 M14
#define M16 M15 M15
#define M17 M16 M16
M17

The times I get on the preprocessed file are:

14:
real    0m0.276s

15:
real    0m0.918s

16:
real    0m3.471s

17:
real    0m18.028s
Quuxplusone commented 6 years ago
I still get:

clang: 15.57s
gcc: 0.16s