This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: PCH, and more generally C++ parser performance
>>>>> "Zack" == Zack Weinberg <zack@wolery.cumb.org> writes:
>> - Sort the pointers when marking to improve locality.
Zack> I tried to do this, misunderstood the way ggc_mark_trees
Zack> works, and wound up calling qsort on every iteration.
Zack> Obviously that was worse.
I tried it too, using radix-sort (which has better asymptotic
complexity that qsort, although not necessarily better wall-clock
time), but I couldn't get a win, even on a case that was causing heavy
paging. I think I just blew it somehow -- it should help.
>> The language really doesn't let you do that. You have to
>> parse everything. Example:
>>
>> template <class T> struct S { static int i; };
>>
>> template <class T> int S<T>::i = f();
>>
>> inline void g () { S<int>.i = 7; }
>>
>> This program requires you to instantiate `S<int>::i', even if
>> you don't need `g'.
Zack> I don't understand C++ well enough to know why. In fact, I
Zack> can't parse
Zack> template <class T> int S<T>::i = f();
Oh. That's called a "static data member". Think of it as a global
variable, but inside a class scope. There's only one such thing
(that's why it's global) -- as opposed to a field, or ordinary data
member, of which there is one per object.
Zack> at all. Note that in this example the only text I would
Zack> defer processing would be the body of g -
Zack> { S<int>.i = 7; }
The point is that the instantiation -- in the body of G -- causes this
static data member to come in to existence, and I believe the standard
requires that we call `f'. (Which of course might have side-effects.)
Skip parsing `g', and you skip instantiating `S<int>::i', and you
therefore skip the side-effects in `f' ...
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com