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]

Re: GCC speed


> Would you please tell me what is the bottleneck of G++
> for today?

AFAIK, there are two major consumers of compile time in g++ today:
overload resolution, and template instantiation.

When you have lots of functions with the same name, g++ will need some
time for each call, in overload resolution. This is what makes a C
compiler faster: You don't have overload resolution in C. Things get
more tricky due to conversion sequences, which all have to be
computed.

For templates, every instantiation is time-consuming, as it involves
creating a deep copy of the template. This nicely combines with
overload resolution: If lookup finds a template function, the
following things must happen:
- deduction of template arguments from the function call arguments
- instantiation of the selected template
- computation of conversion sequences for the instantiated parameters
- participation of the instance in overload resolution.

Please note that the standard library defines a number of template
functions on its own, so you might see more templates than you are
aware of. Template operators are particularly bad, since you need to
look at them every time an operator is used. For example, for strings,
there is an operator

template <class charT, class traits, class Allocator>
inline bool
operator>= (const basic_string <charT, traits, Allocator>& lhs,
	    const basic_string <charT, traits, Allocator>& rhs)
{
  return (lhs.compare (rhs) >= 0);
}

This is considered every time you have >= in your program, and so on.

You may want to check out the development snapshot of gcc and see how
it works, it should have a number of improvements in the area of
compilation speed; although nobody has analysed this in detail, so far.

Hope this helps,
Martin


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