public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* reduce compilation times?
@ 2007-11-27 10:04 mahmoodn
  2007-11-27 11:11 ` Andrew Haley
  2007-11-27 13:48 ` John Love-Jensen
  0 siblings, 2 replies; 69+ messages in thread
From: mahmoodn @ 2007-11-27 10:04 UTC (permalink / raw)
  To: gcc-help


Is it possible to reduce compilation time with GCC?
-- 
View this message in context: http://www.nabble.com/reduce-compilation-times--tf4880765.html#a13967871
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 69+ messages in thread
* Re: reduce compilation times?
@ 2007-11-27 16:07 J.C. Pizarro
  2007-11-27 16:19 ` Brian Dessent
       [not found] ` <5abcb5650711270804o171e1facr565beec70314af75@mail.gmail.com>
  0 siblings, 2 replies; 69+ messages in thread
From: J.C. Pizarro @ 2007-11-27 16:07 UTC (permalink / raw)
  To: Sven Eschenberg, gcc-help

On 2007/11/27, Sven Eschenberg <eschenb@cs.uni-frankfurt.de> wrote:
> Aside from using -j on HT/Mulitcore/Multi-CPU Systems and ccache it might help to put
> the sourcecode into a ramdisk for compilation (no ccache needd then), or at least
> the build directory, for all the temporary stuff.
>
> -Sven

Here the list of how to try to reduce the compilation times:
* to put more RAM of higher frequencies and lower latencies
* to put more machines with more cores per chip (quadcore?),
   bigger caches (8 MiB L2?) and higher frequencies
* to link /tmp to /ramdisk/tmp (mount -t tmpfs)
* to configure the kernel for SMP workloads
* distcc
* make -j N
* ccache
* to recompile optimized gcc, binutils, ELF loader ld, ...
* to use strip --strip-all
* to use -O3 -fomit-frame-pointer -funroll-loops -finline-functions -fpeel-loops
* to use SSE2/SSE/AltiVec (SSE3 is little bit slower)
* to disable shared (it reduces linking time and paging time), to
enable -static.
* to recompile the shared libraries (that it depends) to static libraries.
* to disable threads (they reduce I/O bandwith) if the program
  doesn't require threading
* to disable checking (-DNDEBUG)
* to modify optimizing their sources after profiled the runned
testsuite (-pg, gprof)

Sincerely, J.C.Pizarro

^ permalink raw reply	[flat|nested] 69+ messages in thread
* RE: reduce compilation times?
@ 2007-11-28  7:57 Duft Markus
  2007-11-28 12:01 ` J.C. Pizarro
                   ` (2 more replies)
  0 siblings, 3 replies; 69+ messages in thread
From: Duft Markus @ 2007-11-28  7:57 UTC (permalink / raw)
  To: Tom St Denis, NightStrike; +Cc: J.C. Pizarro, Galloth, gcc-help

Hi!

I assume, that all strategies discussed here are targeted at C. now what
about C++, how do things behave there? As far as i know C++ is much
different, and requires completely different thinking with regards to
splitting source in more files, etc.

Cheers, Markus

Tom St Denis <> wrote:
> NightStrike wrote:
>> On Nov 27, 2007 11:43 AM, Tom St Denis <tstdenis@ellipticsemi.com>
>> wrote: 
>> 
>>> This is why you should re-factor your code as to contain only one
>>> [or as few as possible] exportable functions per unit.
>>> 
>> 
>> Just so I understand (and I realize that this would not be done), but
>> let's say that I have a machine that can compile extraordinarily
>> quickly, and compile time was not a factor.  Is there a difference in
>> the speed of the resulting program when everything is split into many
>> object files instead of being combined into a single main.c, or is
>> the resulting binary identical bit for bit?
>> 
> 
> The only time it would matter (legally) is if there was inline'ing. 
> And really, you should be setting that up yourself with the "inline"
> tag (or macros).
> 
> suppose you had something like
> 
> int myfunc(int x)
> {
>    return x * x + x * x;
> }
> 
> and you only called it from main like
> 
> int main(void)
> {
>    int res;
>    res = myfunc(0);
> }
> 
> Can the compiler special case optimize it?  Well, strictly yes, the
> compiler could inline "myfunc" then reduce it.  Suppose "myfunc" is
> more complicated or larger and it couldn't be inlined.  If the
> compiler could determine the result at buildtime it would be legal to
> optimize it out, but if it can't it won't and it will call the
> function.  So really, in all but the trivial cases [dead code, etc]
> having everything in one unit, especially when your functions aren't
> static, won't help reduce code size or speed.
> 
> What you really should do, is profile your code, then create "static
> inline" or macro copies of heavily used (and not overly large) pieces
> of code.  And even then, inlining code doesn't always help.
> 
> Putting everything in one big file has several disadvantages though:
> 
> -  It increases build time, every time you build it [which could be
> 1000s of times]
> -  It makes content control harder since you have to lock larger
> portions of the project to work on it
> -  It makes editing harder as you have more to scroll/look through
> -  It decreases [not always though] the ability to use smart linking,
> which can increase image size
> -  It makes building on smaller machines [with less ram, slower
> processors, etc] harder
> 
> Ideally, but this isn't a hard set rule, you want to keep each source
> file under 200-300 lines (excluding tables).  It's not a sin to
> violate it here or there where it makes sense.  Most of the time
> though, it's a good idea to try for it.
> 
> In both of my OSS projects, the average file has 1 function in it, and
> is ~150-200 lines per file.  The exceptions being machine generated
> code (e.g. unrolled multipliers), and lookup tables for
> hashes/ciphers. 
> 
> Tom


-- 
5. Dezember 2007
Salomon Automation am  Schweizer Forum fur Logistik, Lausanne, CH




Salomon Automation GmbH - Friesachstrasse 15 - A-8114 Friesach bei Graz
Sitz der Gesellschaft: Friesach bei Graz
UID-NR:ATU28654300 - Firmenbuchnummer: 49324 K
Firmenbuchgericht: Landesgericht fur Zivilrechtssachen Graz

^ permalink raw reply	[flat|nested] 69+ messages in thread
* RE: reduce compilation times?
@ 2007-11-28 12:36 Duft Markus
  0 siblings, 0 replies; 69+ messages in thread
From: Duft Markus @ 2007-11-28 12:36 UTC (permalink / raw)
  To: John (Eljay) Love-Jensen, Tom St Denis, NightStrike
  Cc: J.C. Pizarro, Galloth, gcc-help

John (Eljay) Love-Jensen <mailto:eljay@adobe.com> wrote:
> Hi Duft,
> 
>> I assume, that all strategies discussed here are targeted at C. now
>> what about C++, how do things behave there? As far as i know C++ is
>> much different, and requires completely different thinking with
>> regards to splitting source in more files, etc.   
> 
> The Large-Scale C++ Software Design by Lakos which I've recommended
> targets C++. 

Hi!

Oh, i must have missed that post ;o) Thanks anyway...

Cheers, Markus

> 
> http://www.amazon.com/dp/0201633620
> 
> HTH,
> --Eljay


-- 
5. Dezember 2007
Salomon Automation am  Schweizer Forum fur Logistik, Lausanne, CH




Salomon Automation GmbH - Friesachstrasse 15 - A-8114 Friesach bei Graz
Sitz der Gesellschaft: Friesach bei Graz
UID-NR:ATU28654300 - Firmenbuchnummer: 49324 K
Firmenbuchgericht: Landesgericht fur Zivilrechtssachen Graz

^ permalink raw reply	[flat|nested] 69+ messages in thread
* RE: reduce compilation times?
@ 2007-11-28 13:25 Duft Markus
  2007-11-28 13:26 ` Tom St Denis
  0 siblings, 1 reply; 69+ messages in thread
From: Duft Markus @ 2007-11-28 13:25 UTC (permalink / raw)
  To: Fabian Cenedese, gcc-help

Hi!

Fabian Cenedese <> wrote:
>>> Splitting C files is different to splitting C++ files or splitting
>>> Java files, Fortran, Ada, ObjC, ....
>> 
>> In the case of C++, you can just put each method of a class in a
>> separate .C file.  Provided they all include a .H file which defines
>> the class prototype it's ok.  
> 
> The problem may not be the .cpp but the .h files. If I add a new
> member 
> or method all files of this class need to be rebuilt. With the
> independent functions in C this may be easier to do. But still, if
> everything is rebuilt then it doesn't matter how many files you
> spread your code over. 
> 
> Of course from maintenance point of view splitting files is good
> though 
> I maybe wouldn't go down to function level, more like class level.
> Otherwise the bad overview in the file is just transferred to the
> project level.

+1 ;o) Exactly how i think about it. I personally have a project with
approximately 30K lines, where each .cpp file contains exactly one class
(and it's internal-only stuff...). The project is perfectly
maintainable, further splitting into more files would only make it more
*unmaintainable*, since i would spend my time searching things... ;o)

And as Fabian sayd, in C++ the header files are the problem. It's even
fater to have a class in one C++ file as opposed to having multiple
files, because (with dependency tracking ebnabled) each of the files
including the header (which would be all of those file, right?) will be
rebuilt anyway.

BTW: has gcc a mechanism to determine, wether a change in a header file
affects a particular .cpp file? Microsoft has... They skip every file
where no affecting changes are detected...

Cheers, Markus

> 
> bye  Fabi


-- 
5. Dezember 2007
Salomon Automation am  Schweizer Forum fur Logistik, Lausanne, CH




Salomon Automation GmbH - Friesachstrasse 15 - A-8114 Friesach bei Graz
Sitz der Gesellschaft: Friesach bei Graz
UID-NR:ATU28654300 - Firmenbuchnummer: 49324 K
Firmenbuchgericht: Landesgericht fur Zivilrechtssachen Graz

^ permalink raw reply	[flat|nested] 69+ messages in thread
* RE: reduce compilation times?
@ 2007-11-28 13:56 Duft Markus
  2007-11-28 14:35 ` Tom St Denis
  2007-11-29  0:23 ` Tim Prince
  0 siblings, 2 replies; 69+ messages in thread
From: Duft Markus @ 2007-11-28 13:56 UTC (permalink / raw)
  To: Tom St Denis; +Cc: Fabian Cenedese, gcc-help

Hi!

> This is where automated tools come in handy.  In my projects, I have
> scripts that pick up source files and insert them into the
> makefile(s). So with very little fuss I can add new files (either new
> functionality or new split up code).
> 
> It really depends on the size of the class whether factoring makes
> sense or not.  but if you have heaps of 3000+ line long functions, I
> suspect you spend enough time searching through them as is.
> 
> When I was working on DB2 and scouring their often 6000+ line files
> looking for why GCC 4.whatever.beta wasn't working as hot as it could,
> it wasn't exactly a lot of fun.

I agree with such big files beeing no fun at all. I managed to keep a
structure where files don't get longer than say 500 lines.

> 
> 
>> BTW: has gcc a mechanism to determine, wether a change in a header
>> file affects a particular .cpp file? Microsoft has... They skip
>> every file where no affecting changes are detected...
>> 
> Can't a makefile do that?
> 
> file.o: file.H file.C
> 
> Yes that works fine with GNU Make
> 
> -bash-3.1$ make
> make: `ctmp1.o' is up to date.
> -bash-3.1$ touch ctmp.H
> -bash-3.1$ make
> g++    -c -o ctmp1.o ctmp1.C
> -bash-3.1$ cat Makefile
> ctmp1.o: ctmp.H ctmp1.C
> 
> It's almost like, if you engineer your builds correctly, these are
> "non-issues."
> 
> I don't want to make this personal, but honestly, if you're going to
> try and give out advice, at least know what you are talking about. 
> There are actual proper ways to do things that reduce errors, increase
> productivity, etc, etc.

You didn't get the question: i was asking if a *change* in a header is
recognized to affect a *certain* .cpp file, not how make handles
dependencies and updates targets. Micorosft recognizes that a change in
a certain struct inside a header file may not require a recompilation of
a certain .cpp file if it doesn't use that struct. Thats what i asked
for.

Also i have absolutely no problem with managing my builds correctly. One
part of my job is organizing, managing and building about 80 software
packages...

As far as getting personal is concerned: You are free to get personal if
you like, still i really know very well what i'm talking about, since im
make my money with this. You can easily recognize things that i don't
know by those question marks behind my sentences.

Cheers, Markus

> 
> Tom


-- 
5. Dezember 2007
Salomon Automation am  Schweizer Forum fur Logistik, Lausanne, CH




Salomon Automation GmbH - Friesachstrasse 15 - A-8114 Friesach bei Graz
Sitz der Gesellschaft: Friesach bei Graz
UID-NR:ATU28654300 - Firmenbuchnummer: 49324 K
Firmenbuchgericht: Landesgericht fur Zivilrechtssachen Graz

^ permalink raw reply	[flat|nested] 69+ messages in thread
* Re: reduce compilation times?
@ 2007-11-28 16:06 J.C. Pizarro
  2007-11-28 16:16 ` Tom St Denis
  0 siblings, 1 reply; 69+ messages in thread
From: J.C. Pizarro @ 2007-11-28 16:06 UTC (permalink / raw)
  To: gcc-help, Tom St Denis

On 2007/11/28, Tom St Denis <tstdenis@ellipticsemi.com> wrote:
> As I said in my first post on the subject, there is no "hard set"
> rule about when to refactor. If your class has 3 methods and
> is 75 lines of code, it's probably better to have it all organized
> in one unit/file. But if your class has 15 methods, and requires
> 1500 lines of code, you're probably better off refactoring it.

Well, and how is this GCC in reality?

svn://gcc.gnu.org/svn/gcc/trunk
$ svn info
...
Revision: 130486
...
Last Changed Date: 2007-11-28 02:09:35 +0100 (Wed, 28 Nov 2007)

find . -type f -iregex '.*\.c.*\|.\*.h.*' | grep -v '\.svn' | xargs ls -l | \
   tr -s ' ' | cut -d' ' -f5,8 | sort -nr | head -200 | cut -d' ' -f2 | \
   while read F ; do wc -l "$F" ; done | sort -nr | head -20 | awk \
   '{ printf substr($2,3) ":\t\t" $1 " lines, " ; \
      system("echo -n $(ls -l " $2 " | tr -s \\\\040 \\\\t | cut -f5)") ; \
      print " bytes." }'

Here is the list of the 20 first big files (sorted by KLOCs):

libgcc/config/libbid/bid_binarydecimal.c:               147484 lines,
6403812 bytes.
gcc/config/i386/i386.c:         25308 lines, 815664 bytes.
libjava/gnu/gcj/convert/Unicode_to_JIS.cc:              23139 lines,
625205 bytes.
gcc/config/rs6000/rs6000.c:             21799 lines, 689671 bytes.
gcc/cp/parser.c:                20557 lines, 626246 bytes.
gcc/config/arm/arm.c:           18711 lines, 549174 bytes.
libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/17_hyperg/check_value.cc:
          17196 lines, 823435 bytes.
gcc/cp/pt.c:            16087 lines, 501737 bytes.
gcc/fold-const.c:               15206 lines, 482273 bytes.
gcc/dwarf2out.c:                14990 lines, 453585 bytes.
gcc/combine.c:          13041 lines, 429100 bytes.
gcc/builtins.c:         13026 lines, 397350 bytes.
gcc/config/mips/mips.c:         12531 lines, 393171 bytes.
gcc/cp/decl.c:          12341 lines, 386701 bytes.
gcc/config/sh/sh.c:             10932 lines, 329618 bytes.
gcc/config/alpha/alpha.c:               10727 lines, 294299 bytes.
libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/14_ellint_3/check_value.cc:
        10116 lines, 391467 bytes.
gcc/expr.c:             10102 lines, 317028 bytes.
gcc/config/ia64/ia64.c:         9970 lines, 294743 bytes.
gcc/config/frv/frv.c:           9594 lines, 285369 bytes.

They are between 147.4 and 9.5 Klines in comparison
to 1.5 Klines of code that you wish.

There is much work to refactor the GCC's {.c/.h} sources.

   J.C.Pizarro

^ permalink raw reply	[flat|nested] 69+ messages in thread

end of thread, other threads:[~2007-12-05 10:29 UTC | newest]

Thread overview: 69+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-27 10:04 reduce compilation times? mahmoodn
2007-11-27 11:11 ` Andrew Haley
2007-11-27 11:15   ` mahmoodn
2007-11-27 11:30     ` Andrew Haley
2007-11-27 12:20       ` mahmoodn
2007-11-27 12:25         ` John Love-Jensen
2007-11-27 15:27           ` Tim Prince
2007-11-27 14:07         ` Andrew Haley
2007-11-28  9:01           ` mahmoodn
2007-11-28 12:11             ` John (Eljay) Love-Jensen
2007-11-30  9:15               ` mahmoodn
2007-11-30 13:33                 ` mahmoodn
2007-11-27 15:48   ` Sven Eschenberg
2007-11-27 16:27     ` Andrew Haley
2007-11-27 18:51       ` Sven Eschenberg
2007-11-27 19:21         ` Andrew Haley
2007-11-27 20:43           ` Sven Eschenberg
2007-12-01 12:20   ` mahmoodn
2007-12-03 16:14     ` Andrew Haley
2007-12-04 11:23       ` mahmoodn
2007-12-04 12:19         ` Tom Browder
2007-12-05  7:44           ` mahmoodn
2007-12-05 10:24             ` Tom Browder
2007-12-05 10:29               ` mahmoodn
2007-11-27 13:48 ` John Love-Jensen
2007-11-27 16:07 J.C. Pizarro
2007-11-27 16:19 ` Brian Dessent
2007-11-27 16:26   ` J.C. Pizarro
     [not found] ` <5abcb5650711270804o171e1facr565beec70314af75@mail.gmail.com>
2007-11-27 16:41   ` J.C. Pizarro
2007-11-27 16:46     ` Tom St Denis
2007-11-27 17:16       ` J.C. Pizarro
2007-11-27 17:46         ` Tom St Denis
2007-11-27 18:26           ` Wesley Smith
2007-11-27 19:35       ` NightStrike
2007-11-27 19:41         ` John (Eljay) Love-Jensen
2007-11-27 19:49         ` Tom St Denis
2007-11-28  9:19           ` Brian Dessent
2007-11-28 12:07             ` Tom St Denis
2007-11-28 12:35               ` Brian Dessent
2007-11-27 17:44     ` Vladimir Vassilev
     [not found]       ` <998d0e4a0711271310k657b791cy6ad5cc5721105f4c@mail.gmail.com>
2007-11-27 22:30         ` J.C. Pizarro
2007-11-28  7:57 Duft Markus
2007-11-28 12:01 ` J.C. Pizarro
2007-11-28 12:28   ` Tom St Denis
2007-11-28 12:49     ` Fabian Cenedese
2007-11-28 13:03       ` Tom St Denis
2007-11-28 12:52     ` J.C. Pizarro
2007-11-28 13:17       ` Tom St Denis
2007-11-28 13:40         ` J.C. Pizarro
2007-11-28 13:51           ` Tom St Denis
2007-11-28 13:59             ` Tom St Denis
2007-11-28 15:51             ` John (Eljay) Love-Jensen
2007-11-28 13:30       ` Ted Byers
2007-11-28 12:12 ` John (Eljay) Love-Jensen
2007-11-28 12:31   ` J.C. Pizarro
2007-11-28 12:39     ` Tom St Denis
2007-11-28 12:54     ` John (Eljay) Love-Jensen
2007-11-28 12:18 ` Tom St Denis
2007-11-28 13:09   ` Ted Byers
2007-11-28 12:36 Duft Markus
2007-11-28 13:25 Duft Markus
2007-11-28 13:26 ` Tom St Denis
2007-11-28 13:56 Duft Markus
2007-11-28 14:35 ` Tom St Denis
2007-11-29  0:23 ` Tim Prince
2007-11-28 16:06 J.C. Pizarro
2007-11-28 16:16 ` Tom St Denis
2007-11-28 16:34   ` J.C. Pizarro
2007-11-28 18:18     ` Tom St Denis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).