Open Quuxplusone opened 13 years ago
Attached syscache-preprocessed.c
(375133 bytes, text/plain): Preprocessed syscache.c C source file from Postgres source
Sanity test: Are you using a debug build of clang? Or is it a release build without assertions?
(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.
(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
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
This might be the revenge of insanely long redeclaration chains; it's happened before with Postgres.
This is also rdar://problem/9907018
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.
Assigning to myself for now.
I find this bug amusing and I am trying to code a solution. No promises it will actually work.
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
I still get:
clang: 15.57s
gcc: 0.16s
syscache-preprocessed.c
(375133 bytes, text/plain)