This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Optimization Inquiry


It's an old programmers' axiom that 80% of a program's time is spent 
executing 20% of the code.  My analysis confirms this rule of thumb.  
Perhaps even more time is spent executing less code, but my little project 
isn't complete so I can't say for sure.

In analyzing GCC performance, I added some code to the *.c files in the gcc 
directory in order to track which portions of code were being most 
frequently executed.  The culprits, and hence files that should be most 
targeted for optimization, are:

 1. cpplex.c
    (by a landslide; 9x more than any file)
 2. cppmacro.c
 3. cpplib.c

I'd do a top 10, but it really drops off after these three.

NOTE: When I say 'section' of code, I mean:
 1. The beginning of every function, and
 2. At every multiline decision branch except switch/case.  In other words, 
every while, do/while, for, if, if/else, else/if, else that spanned across 
multiple lines was logged.  Changing the code to log single line decision 
branches and switch/case branches would take up too much of my time.

NOTE: My analysis is not complete.  I was only able to analyze files a*.c 
through c*.c.  In other words, there may be some file worse than those I 
mentioned hiding out in d*.c through x*.c, but it's too early to tell.

Particularly noteworthy is the a while loop in the cpplex.c file on lines 
264 - 293.  This loop is the primary cause of the cpplex.c file being such 
a poor performer.  This loop spends:

 1. 1.08% of its time executing skip_escaped_newlines(pfile) on line 271,
 2. 1.23% of its time executing the if decision branch on lines 275-288,
 3. 4.71% of its time executing adjust_column(pfile) on line 292,
 4. 7.10% of its time executing handle_newline(pfile) on line 290

for a total of 14.1% of the while loop's time.  The remainind 85.9% of its 
time is spent executing a single line of code, line 266.  (Correct me if 
I'm wrong, but isn't that two seperate statements crammed into one line?)

Unfortunately, I'm not familiar enough with the gcc project, the functions 
within the cpplex.c file, etc. to know how or where to begin.  If someone 
could help me, and the GCC development team, to optimize the section of 
code I just described, we'd all be grateful.

I don't know if simply changing a few lines will do or if the whole file 
needs to be rewritten.  I'm just giving you a heads-up on what needs to be 
done.

NOTE: All references are to gcc version 3.3.1.  I want to be able to use and 
test on a stable version of gcc to know that whatever problems may be 
encountered are a result of the optimizations.

Joseph D. Wagner


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]