Author Topic: Improving compile and link speeds of C++ projects  (Read 5428 times)

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Improving compile and link speeds of C++ projects
« on: April 12, 2006, 03:33:54 pm »
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

  • Guest
Re: Improving compile and link speeds of C++ projects
« Reply #1 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.


Offline squizzz

  • Almost regular
  • **
  • Posts: 132
Re: Improving compile and link speeds of C++ projects
« Reply #2 on: April 12, 2006, 11:08:53 pm »
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. :)
« Last Edit: April 12, 2006, 11:15:12 pm by squizzz »
this space is for rent

Anuk

  • Guest
Re: Improving compile and link speeds of C++ projects
« Reply #3 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.

takeshimiya

  • Guest
Re: Improving compile and link speeds of C++ projects
« Reply #4 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.

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.
« Last Edit: April 13, 2006, 12:04:20 am by Takeshi Miya »

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Improving compile and link speeds of C++ projects
« Reply #5 on: April 13, 2006, 01:33:01 pm »
I would add distributed compilation 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

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Improving compile and link speeds of C++ projects
« Reply #6 on: April 13, 2006, 08:54:24 pm »
And also on Linux (thanks to daniel2000 for the info :)), the use of ccache could be particularly useful in speeding up compilation process :).

Best wishes,
Michael