Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: Michael on April 12, 2006, 03:33:54 pm

Title: Improving compile and link speeds of C++ projects
Post by: Michael on April 12, 2006, 03:33:54 pm
Hello,

I have found this small, but IMHO relatively interesting article (http://www.rakkar.org/blog/?p=69) in the Rakkar's Blog. I think it could be useful (especially to newbies) to improve compile and link speeds of C++ projects.

Best wishes,
Michael
Title: Re: Improving compile and link speeds of C++ projects
Post by: Anuk on April 12, 2006, 10:55:35 pm
Interesting.

I want to add here something:

- using precompiled headers. gcc, msvc know about them and really speed up.

Title: Re: Improving compile and link speeds of C++ projects
Post by: squizzz on April 12, 2006, 11:08:53 pm
I would add distributed compilation (http://distcc.samba.org/) to the above ideas. Well, at least when you use GNU/Linux and have more machines available. :P

Btw. distcc GUI frontend would be nice idea for a plugin I guess. :)
Title: Re: Improving compile and link speeds of C++ projects
Post by: Anuk on April 12, 2006, 11:22:54 pm
yes, distcc is very nice solution, when you can use more systems for your work, agreed, but most of the times, not all users want to share sources across the network or share them at all.
Title: Re: Improving compile and link speeds of C++ projects
Post by: takeshimiya on April 12, 2006, 11:35:07 pm
Here are some good techniques by Herb Sutter: http://www.gotw.ca/publications/mill04.htm

Resumed:
o Avoid gratuitous #includes. Use forward declarations whenever a definition isn't required. (For forward declaring iostreams, use the header <iosfwd>).

o Avoid unnecessary membership. Use the Pimpl Idiom to fully hide a class' private implementation details. This is a design choice, and a very important one. An example where you can see it working is OMGUI (http://www.omgui.org/).

o Avoid unnecessary inheritance. Prefer composition/membership over inheritance wherever possible.


A technique to decrease linking time (specially when using an external library) is linking directly to the DSO (.dll).
This technique is frequently used in linux, but not so well known in win32. Latests versions of MinGW support it.
To see a real world example in C::B, look at the Ogre3d C::B project samples (http://ogre3d.org/).

If using GCC4, make use of the Visibility flag (http://gcc.gnu.org/wiki/Visibility).
It improves load times of the DSO, let's the optimiser produce better code, reduces the size by removing unnecessary symbols, producing much lower chance of symbol collision and faster linking time.
Title: Re: Improving compile and link speeds of C++ projects
Post by: Michael on April 13, 2006, 01:33:01 pm
I would add distributed compilation (http://distcc.samba.org/) to the above ideas. Well, at least when you use GNU/Linux and have more machines available. :P

distcc seems to work on Cygwin too, which is IMHO a good thing :).


Btw. distcc GUI frontend would be nice idea for a plugin I guess. :)

Yes, I think it would nice to have such a plugin for C::B :), especially for people having more than one machine or available network resources.

Best wishes,
Michael
Title: Re: Improving compile and link speeds of C++ projects
Post by: Michael on April 13, 2006, 08:54:24 pm
And also on Linux (thanks to daniel2000 for the info :)), the use of ccache (http://ccache.samba.org/) could be particularly useful in speeding up compilation process :).

Best wishes,
Michael