User forums > General (but related to Code::Blocks)

Improving compile and link speeds of C++ projects

(1/2) > >>

Michael:
Hello,

I have found this small, but IMHO relatively interesting article 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

Anuk:
Interesting.

I want to add here something:

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

squizzz:
I would add distributed compilation 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. :)

Anuk:
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.

takeshimiya:
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.

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.

If using GCC4, make use of the Visibility flag.
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.

Navigation

[0] Message Index

[#] Next page

Go to full version